Print

Print


A jar file is basically a kind of zip file of a directory (in MASON, it'd be the 'sim' directory) with an additional file stored inside it called a "Manifest" which declares some facts about the contents of the jar file.  Notably, the Manifest can state which class gets launched if you execute the Jar file -- double click on it or whatnot.  You'd want that class to be your UI class.  For example, if you wanted to launch the Ant demo, you'd put sim.app.antsforage.AntsForageWithUI in there.

Thus a simple Manifest has just a single line:

	Main-Class: sim.app.antsforage.AntsForageWithUI

... and that's it!  So see if you can follow the procedure when doing "make jar" with the Makefile.  First, it compiles everything.  Then: 

        touch /tmp/manifest.add
        rm /tmp/manifest.add
        echo "Main-Class: sim.display.Console" > /tmp/manifest.add
        jar -cvfm jar/mason.${VERSION}.jar /tmp/manifest.add `find . -name "*.class"` `find sim -name "*.jpg"` `find sim -name "*.png"` `find sim -name "*.pbm"` `find sim -name "index.html"` sim/display/simulation.classes sim/display/simulation.classes

The first three lines basically create a file called /tmp/Manifest.add which contains the one line above.  The fourth line gathers together all of the following in the 'sim' and 'ec' directories:

	- All class files
	- All jpg files
	- All png files
	- All pbm files
	- All index.html files
	- The files sim/display/simulation.classes and sim/display/simulation.classes

This stuff gets all bundled into a jar file, with a manifest copied from the /tmp/Manifest.add file you made.  And you're done.

Some notes:

1. As written above, the jar file would launch sim.display.Console, not sim.app.antsforage.AntsForageWithUI or whatnot.  sim.display.Console pops up the app-chooser window.  You can customize that window to only display your application by editing the sim/display/simulation.classes file to only have your application's UI class name (like sim.app.antsforage.AntsForageWithUI).

2. You could also replace sim.display.Console with your UI class name (like sim.app.antsforage.AntsForageWithUI) so it's directly launched, rather than popping up the chooser window first.

3. This jar file does NOT contain external libraries, notably jmf.jar, itext.jar, jcommon.jar, jfreechart.jar, etc.  If you want those facilities, you'll need to include those jar files in your application as well.

Sea


On Mar 25, 2013, at 11:12 PM, Steve Kraska wrote:

> Thank you everyone for such quick and helpful responses. So I just want to make 
> sure I understand all of this correctly since it is my first real experience with jar 
> files. I imagine my process of getting from my project to executable application as 
> follows:
> 
> 1.) As discussed in the PDF support doc, going into the proper directory in mason 
> and running the unix command:   make jar 
> 
> 2a.) Taking the resulting jar file and using Launch4j (since it is open source) to 
> create an executable.
> 
> 2b.) Making sure to add lib/* to the "Classpath" in the respective tab in the 
> Launch4j GUI when making the executable.
> 
> Is this right? I'm mostly concerned about step 1 as I don't know if this is the right 
> way to make a jar to be used in an executable application. If it is, in which folder 
> do I run make jar? The PDF was not very clear on that.
> 
> Once again, thank you so much,
> Steve Kraska