• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JAR tool

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic