Take the 2-minute tour ×

I'm currently working on my own little video game in Java, but as of now when i give the Runnable Jar file to someone so they can play, i have to send them 22 other resource files which are required, and have them place it in the same folder. This is unbelievably inconvenient and i know that there is a way to automatically package these resources into the runnable jar file. If i cant do this then i would like to at least know how to access the files in the Runnable Jar so i could simply copy paste the files inside. I have combed the internet and no suggestions have worked. I can run the program properly in eclipse if i use this code:

    URL url = this.getClass().getResource("Jugger-Nog.jpg");
         image = ImageIO.read(new File(filePath));
         //image = ImageIO.read(url);

The first line creates a url, which is what i read on many web pages, but using that and the 3rd line of code did not work in the JAR or in Eclipse, but the second line on its own will work just fine in Eclipse. Any ideas, because the internet doesnt have many.

share|improve this question
you can use URL url =Thread.currentThread().getContextClassLoader().getResource("Jugger-Nog.jpg");, but make sure that image file should be on your class' root folder. –  Asad Rasheed Jul 18 '11 at 6:40
Perhaps you'll find this answer helpful? –  oferei Jul 18 '13 at 8:57
add comment

3 Answers

Is it so bad put the JAR file and the resource files just into the same directory, rather than package all of it inside the JAR?

You could package your game on an Installer which copies all of it to the Program's folder and puts some shortcuts.

share|improve this answer
add comment

I had this problem too, but my solution was that the program checks if a folder in %app data%/roaming/ called for myApp exists. If it doesn't the program does a mkdir and makes that folder. Then it's just to let the program know the location of where all the source files is located. No need to hockey pokey around with your files.

share|improve this answer
add comment

You should use:

InputStream in = this.getClass().getResourceAsStream("Jugger-Nog.jpg");
image = ImageIO.read(in);
share|improve this answer
add comment

Your Answer


