File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes JAR tool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JAR tool" Watch "JAR tool" New topic

JAR tool

Aaron O'Brien
Ranch Hand

Joined: May 24, 2002
Posts: 89
Hi everyone,

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:

Main-Class: MyMainClassName

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!
Aaron O'Brien
Ranch Hand

Joined: May 24, 2002
Posts: 89
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 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!
I agree. Here's the link:
subject: JAR tool
jQuery in Action, 3rd edition