Exporting as .jar in eclipse

Hey,
I just finished the alpha of my project and wanted to export it as a runnable .jar file.
To do this, I click on File -> Export…, select "runnable .jar file"and click “next”.
Now, I select the Launch configuration and select an export destination. I accept it and export the .jar file.
After this, I ran the .jar, and it worked a bit. Everything’s alright but the images and sounds. I don’t see any images and don’t hear any sounds. Things(rectangles etc.) I drew using Graphics class are shown.
That’s the way I load the Images:


try {
    skin = ImageIO.read(new File("res/guys/" + skinname +".png"));
} catch (Exception e) {System.out.println("eror loading skin at guy.java");}

That’s the java project.

http://i.epvpimg.com/6bt1c.png

The .jar looks like this:

org
  |
  +---> eclipse --> jdt --> internal --> jarinjarloader --> some classes ;)
META-INF
  |
  +---> MAINFEST.MF
com
  |
  +---> companyname --> projektname --> my classes

I don’t know where to place the resources. How can I handle and solve this problem?

You should not load your resources that way.

Check this article:
http://www.cokeandcode.com/index.html?page=tutorials/webstart

Skip to the part “Getting at your resources”, you’ll see how you should do it and why.

you can also place the resources outside the jar and it will work.
however it wont work with applets and webstarts because these want to have it all in one jar (many jars is possible maybe, but jars nonetheless)

I put my resources in a package in the src folder, usually a subfolder, but at least something I can get to via a “…/” or two if needed.

For example in the SimplexTexture tutorial I am working on, I have a packages called:

com.adonax.tutorial (for the code)
com.adonax.tutorial.images (for the images)

Code in the tutorial area (TutorialFramework is a class in this source folder) that loads a resource image would form the URL form as in the following:


		URL introURL = TutorialFramework.class.getResource(
				"images/classicClouds.JPG");

I think this method is consistent with what is presented in the Java Tutorials. There is a description of resource loading under the topic of icons (go figure) that wasn’t easy for me to find but I now have bookmarked:
http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html
See the section titled “Loading Images using getResource” about 1/3rd of the way down.

I don’t know that this is best, only that it works for me.

Second note: I’ve never had much success with selecting export to “Runnable JAR file”, and always the first option “JAR file”. I confess I haven’t bothered to learn the significance of the distinction, since the “JAR file” option works fine.

In general, I’ve found URLs to be the most reliable way to identify various files and resources, especially since subfiles in a compressed jar are kind of a special case and the File command can’t necessarily peek inside a compressed file.

P.S., the author of “cokeandcode” is pretty reliable. I didn’t look at his suggestions in this instance, but I’m betting there are good suggestions there.