• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Executable jars!

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

This is probably a neverending, inexhaustable subject...

I'm trying to jar my game, and all is well until I try to run it. It runs like a charm when doing "java -jar Arkanoid.jar", but it seems my classes can't reach my images, contained in folder Images, and I can't double click on the jar file to start the game.

My game folder looks like:

arkanoid
|
-all classes
-subfolder Images, contains all images.
-subfolder src, contains all src.

in the arkanoid/ folder, I do the following:

jar cmf MANIFEST.MF Arkanoid.jar *.class Images src

MANIFEST.MF contains one row of text:

Main-Class: GameBoardMultBall[enter]

When I do this, I see that all images are compressed and put into the jar file, but why doesn't it work?

/Kaspar
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without seeing your code, I can only guess that to load an image, you're currently doing something like

java.awt.Image image = java.awt.Toolkit.getDefaultToolkit().getImage("images/moosefly.gif");

This won't work when everything is all jarred up. For this situation, you'll want to make use of java.net.URLClassLoader, as described in the "Using JAR-related APIs Introduced in 1.2" lesson of Sun's Java Tutorial.

java.awt.Image image = java.awt.Toolkit.getDefaultToolkit().getImage(java.net.URLClassLoader.getSystemResource("images/moosefly.gif"));

I can verify that this does work, as I just tested it.

For more complete steps to creating a working demo, I'll post an addition to the "Creating an Executable JAR File" thread.
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, darn there, sheriff..!

Since you're a 100% right on how I currently load my images, a good guess would be that your tested solution works just as well! I'll give it a try.

Thanks a bunch!

Sincerely, Kaspar
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic