I have an application that I am trying to jar so it would be executable when double clicked. The application contains 2 images. I have created a Manifest.txt file that contains one line:
Then I execute the following in the command line:
jar cfm MyApp.jar Manifest.txt *.*
The jar file is created and when you double click the file, everything seems to work correctly. The splash screen opens and a short moment later you can see the GUI. However, when you move the MyApp.jar file to another location on the same computer (or on another computer) the splash screen does not appear when the application is started. The GUI does start.
I checked to make sure the JPEG files are in the JAR file by executing the following in the command line:
jar tf MyApp.jar
and the images are listed in the JAR file. So I must be missing something here whether it is in code or in the Manifest file. Any sugestions would be appreciated.
Thanks for your time!
Joined: May 24, 2002
Ok, I've figured it out. Just thought I'd share this with anyone who was interested.
When referencing files other than class files in the jar, you need to use the following line of code in the application:
Make sure to import the java.net package...
Then specify url when getting the image. getResource() gets the image in the JAR file.
Once you create your MANIFEST and specify the Main-Class, you would then jar the application. I used :
c - indicates that you want to create a JAR file.
f - indicates that you want the output to go to a file rather than to stdout.
m - Used to include information in the MANIFEST.txt I created in the default manifest created by the jar utility. This is why we specify the Main-Class.
Now when you create the jar, you can move that single file anywhere you want. Multiple files are no longer needed. The JAR utility automatically compresses the files by default (but this can be turned off with the 0 parameter).
Hope you find this to be useful...and as fun as I did!