Computer Association of SIUE - Forums

CAOS Forums => Questions and Answers => Topic started by: Brad Nunnally on 2006-10-17T21:06:51-05:00 (Tuesday)

Title: Java Executable
Post by: Brad Nunnally on 2006-10-17T21:06:51-05:00 (Tuesday)
Using the Eclipse IDE how in the hell do you make an executable .jar file? I swear it is something simple and i am just missing it.
Title: Re: Java Executable
Post by: William Grim on 2006-10-19T00:42:07-05:00 (Thursday)
Not sure, but I do know that this works on the command-line:


jar cf blah.jar
Title: Re: Java Executable
Post by: Peter Motyka on 2006-10-19T14:13:38-05:00 (Thursday)
Typically this is achieved using an ANT task which emits a manifest file (MANIFEST.MF) and packs it into the jar file.  The manifest has the name of the class which contains a static  main method which is invoked when you run "java -jar executable.jar".  Rather than muck around with Eclipse, put together and ANT build.xml file and invoke that via Eclipse's ANT tool.  This way you can build the same executable jar file from commandline and avoid an IDE dependency.

http://ant.apache.org/manual/CoreTasks/manifest.html
The attribute needing defined is "Main-Class".
Title: Re: Java Executable
Post by: William Grim on 2006-10-19T17:24:59-05:00 (Thursday)
I took a look at the reasons Ant was created in place of something like GNU/Make.  However, I was still not convinced; why is it a suitable replacement for GNU/Make?

Reason I ask is that GNU/Make already runs on more platforms/architectures than Java.  It's also fairly easy to make sure you write non-OS-dependent Makefiles, even though it does take some experience to do that.

Anyway, I was just curious.
Title: Re: Java Executable
Post by: Peter Motyka on 2006-10-19T18:06:38-05:00 (Thursday)
The annoying syntax of a GNU/Make file is enough to drive someone bonkers.  I'd rather write well-formed XML build files any day.  Also, it is magnitudes easier to write a GUI build-file-maker when your target file output it XML, rather than some awkward text format.

ANT kicks GNU/make butt!
Title: Re: Java Executable
Post by: William Grim on 2006-10-19T21:24:29-05:00 (Thursday)
Hehe, what is annoying about it?  You have targets and dependencies one line, and commands on subsequent tabbed lines.

The most complex parts of Make that I've used are inclusion of multiple files and auto-targets using string substitution.  In fact, I think those are about as difficult as Make syntax and logic can be.

I bet I could write a GUI Makefile builder as easily as you could write a GUI Ant file builder :-)

Also, in vim, it's easy to make sure that tabs are enabled rather than spaces when you press the tab key in a Makefile through some use of conditional statements that are executed in the .vimrc at startup.
Title: Re: Java Executable
Post by: Shaun Martin on 2006-10-20T11:59:05-05:00 (Friday)
 :smartass: