Image location on a Runnable JAR file?
Hello, i am using eclipse to create my java 2d game... i am trying to export it although the problem is that...when i run the game in Eclipse it works perfectly although on the runnable jar file, it doesnt work because none of the images are working.... the images are in the same folder as the classes (Project>src>Package>) so, i use 'src/package/background.png' when in eclipse, although that is not working when exported..
so how do i make it so i can use those images in the exported file... ive tried everythign!!, this is a list of what ive tried:
'src/package/background.png'
'package/background.png'
'background.png'
'./background.png'
'./package/background.png'
'./src/package/background.png'
'project/src/package/background.png'
'./project/src/package/background.png'
but none of these are working (P.S. i also have tried it with // instead of just / )
-thanks in advance!!'
Re: Image location on a Runnable JAR file?
How are you loading the images? If you do so by using getClass().getResource() the path should be relative or absolute (without the src). If the image is the root path of the jar (src folder in your source directory structure), specify the full path "/background.png"
Re: Image location on a Runnable JAR file?
Quote:
Originally Posted by
copeg
How are you loading the images? If you do so by using getClass().getResource() the path should be relative or absolute (without the src). If the image is the root path of the jar (src folder in your source directory structure), specify the full path "/background.png"
im not 100% sure what u mean (i tink)...but this is how i call the image:
Code :
Image bg; // at top of class
//In my Constructor
ImageIcon back = new ImageIcon("src//Game//Background.png");
bg = back.getImage();
and this code works perfectly in eclipse, but not when exported
Re: Image location on a Runnable JAR file?
I struggled with this for a second so would've been nice if someone had spelled this out:
new JLabel(new ImageIcon(getClass().getResource("image.gif"))) works.