• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executable jars!

 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • 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
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic