Reputation: 21
In a program I am making, I need to access images in a folder placed alongside it. The program works fine when I run it with Eclipse, but when I export it to a .jar file, it does not get the location of the folder properly.
File roomF = new File("Assets/Rooms/1/0.png");
In the IDE, roomF
refers to the correct location:
C:\Users\[Username]\Desktop\Eclipse Java\[Project name]\Assets\Rooms\1\0.png
However, in the .jar file, it refers to this:
C:\Users\[Username]\Assets\Rooms\1\0.png.
How can I fix this?
Upvotes: 0
Views: 43
Reputation: 108
There are two solutions to this:
'C:\Users[Username]\Desktop\Eclipse Java'
This way, when you are accessing Assets/Rooms/1/0.png
, it points to the correct location.
0.png
there, hence you wouldn't be needing to place your JAR each time you make a new one as said in step 1.Upvotes: 0
Reputation: 58
You should not have resources outside of your JAR or dependencies that need a local path in order to work. Create a resource folder in your project and load the file from there.
Upvotes: 1