Game Tutorials -->> Creating An Executable JAR File (Beginning Java forum at Coderanch) (original) (raw)
What's next?
Loading an image from a JAR file is the winner.
Note that loading an image from a JAR file is a little bit different than loading an image from an unjarred file.
Save the moose head image at the top left of this page in a directory name "images".
In a different directory named "fubar", compile the following source files.
Foo.java ImagePanel.java
Create and save a file named manifest.txt with the following contents. (Don't forget to include at least one blank line at the end of the file.)
Now, your project directory structure should be as follows.
From the directory that holds fubar, images, and manifest.txt, run the following command.
jar cmf manifest.txt FooJar.jar fubar/* images/*
This should have created a file name FooJar.jar with the same contents as the above directory structure, plus a directory named "META-INF" with a file name "MANIFEST.MF" inside of it.
Delete everything but this FooJar.jar file.
You should be able to execute the JAR with the following command.
java -jar FooJar.jar
A frame should appear, likely without any image displayed. Just resize the frame to trigger a repaint, and the moose head image should appear.
For a description of the java.net.URLClassLoader used to load the image, take a look at the "Using JAR-related APIs Introduced in 1.2" lesson of Sun's Java Tutorial.
What's next?
[ August 20, 2004: Message edited by: Dirk Schreckmann ]