user2680805
user2680805

Reputation: 15

Resources not found... can run in eclipse but not from jar

Hello I'm having a bit of trouble with resource loading in .jar. In eclipse, I create image files with the path "data//guis//play.png" but when I try to run the jar, i get the exception that the resource could not be found, even when packaged in the same structure as I have it within eclipse. How do I rememdy this?

Upvotes: 0

Views: 426

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285415

You state:

Hello I'm having a bit of trouble with resource loading in .jar. In eclipse, I create image files with the path "data//guis//play.png" but when I try to run the jar, i get the exception that the resource could not be found, even when packaged in the same structure as I have it within eclipse. How do I rememdy this?

But that's exactly what your problem is likely due to -- you're trying to create files and files don't exist inside of Jars (as Java sees it). Instead load the images as resources not as files.

For more detailed help, you will want to show more of your pertinent code as well as the structure of your jar file.

Please run this from the command line and show the result here:

jar tf MyJarFile.jar  

Of course you'll use your jar file name when you run this line.

Upvotes: 1

Related Questions