JAR doesn't work in an other directory
Hi,
I create executable JAR files in Eclipse and manually. The JAR contains the CLASS files and images that I use in my program. It works fine but when I move the JAR in an other directory the images don't get visualized. I opened the JAR to make sure that the image files are in and they are there. What's the problem?
Re: JAR doesn't work in an other directory
... what is the structure of your images? Do you have them separated in their own package?
I have my problem where images are not showing up at all. How are you showing them, in code?
Re: JAR doesn't work in an other directory
I just have the images alongside the source/class files and show them by means of the default toolkit getImage() method.
Re: JAR doesn't work in an other directory
I just moved my jar in different directories and I'm seeing the same thing. Once more, the image only shows when I run it from within Eclipse. Is this the same for you?
Well, someone suggested I use the getResource to obtain the url path of the image. When I did that, I'm getting my image where ever I put the jar file.
Code:
URL urlIMG = getClass().getResource("/dir/filename.jpg");
If you use this in place of .getImage(), your image may show up regardless of location of the jar file. Be sure to import the package "java.net.URL"
Re: JAR doesn't work in an other directory
Can I ask what options are you selecting when you create your jar file?
I just want to make sure I am doing it the correct way. I am select the export option under file. From there, I am selecting 'runnable jar'. The launch config is the src/project I'm looking to export. But which are you selecting for your 'library handling'? I'm selecting 'package required libraries' - this only makes sense to me since I don't want to extract or leave out anything. right? what's your method?