0

I have problem in my program (JAVA) that I have configured my code with some Images and Text file paths . I want to create its "Runnable Jar File" I have created one but the PATH is not independent like if I move it to other computer then it will not run cause of the file path I gave it to does not EXIST ... IS THERE ANY WAY TO READ THE FILE PERMANENTLY FROM RUNNABLE JAR ?

some code is

My Package is created like this

try {
    icon = new ImageIcon(ImageIO.read(ResourceLoader.class.getResourceAsStream("/resources/12.jpg")));
    tree = new ImageIcon(ImageIO.read(ResourceLoader.class.getResourceAsStream("/resources/back.jpg")));
    vector = new ImageIcon(ImageIO.read(ResourceLoader.class.getResourceAsStream("/resources/line.PNG")));
} catch(Exception e){
    e.printStackTrace();
}

enter image description here

After Creating Runnable Jar File I am facing Error After Launching JAR file with cmd ,Explorer look like this

enter image description here

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Saad Sadiq
  • 13
  • 1
  • 8
  • Possible duplicate of [How to get the path of running java program](http://stackoverflow.com/questions/17540942/how-to-get-the-path-of-running-java-program) – Gatusko Dec 09 '16 at 21:46
  • this is not what i want actually . I want to permanently store my txt and jpg file on JAR file and when we run jar they will show up from their default paths with in the jar – Saad Sadiq Dec 09 '16 at 21:51
  • http://stackoverflow.com/questions/4056682/how-can-my-java-program-store-files-inside-of-its-jar-file Search a little more – Gatusko Dec 09 '16 at 21:53
  • not convenient :( – Saad Sadiq Dec 09 '16 at 21:59
  • How did you create the JAR file? If you use Eclipse, just select the resources folder to be included in the JAR file. You could also just use a ZIP tool like 7zip to add the resources folder to your existing JAR, allthough I would suggest using a build tool like Maven to build your application. According to the exception you're getting, the resources either don't exist in the JAR or are in the wrong location (e.g. resource folder is not in the root of the JAR). – Quagaar Dec 09 '16 at 23:10
  • Well I will Do this and tell then Thanks mate :) – Saad Sadiq Dec 10 '16 at 14:50

0 Answers0