Take the 2-minute tour ×

I mean I tried to export my java game like this : EXPORT>Jar File but if I do this it doesn't start.

And if I export to executable jar file it doesn't export my resources into the jar file.

I mean if I play the game in eclipse the sound works. But if I export to executable jar file it doesn't work. I guess it is not exporting the sound too.

This is the code I tried to use to launch the jar file :

java jar -cvfe ProjectZero.jar Main.Launcher Main.Launcher.class

share|improve this question
add comment

1 Answer

Here are two solutions for solving this problem, hope this is clear enough:

Solution #1 - You want your resources outside of the JAR file

Just copy/paste the folder containing your resources in the same folder containing the JAR file. (Make sure the directory matches pathes mentioned in the application.)

Solution #2 - You want your resources inside the JAR file

If you want the resources to be directly included in the JAR file, you could use the function getResource() to get the images/sounds. Then make sure that resources are visible in both: "/src" and "/bin" folders.

For example, if you have the following application code:

ImageIcon myIcon = new ImageIcon(this.getClass().getResource("/resources/icon.gif")); 

your file should be visible in:


Then you can export your application as a JAR file, it will contain the resources.

share|improve this answer
it gives me an error.. Cannot instantiate JComponent().. i'm currently using eclipse so maybe that's a problem –  Verdes Andrei Jul 14 '13 at 4:53
and also setIcon(myIcon) is undefined for the type JComponent –  Verdes Andrei Jul 14 '13 at 4:56
@VerdesAndrei It does not matter using Eclipse or not. This piece of code was just an example. You should only pay attention to "this.getClass().getResource("/resources/icon.gif")" to retrieve the path of your resource. –  Guillaume.M Jul 14 '13 at 15:48
add comment

Your Answer


