I developed a little program a while back, which I made into an executable jar-File. It used some images I placed in a separate folder called "cache", which is always in the same directory as the .jar.
consoleBG = ImageIO.read(new File("./cache/consoleBG.png").toURI().toURL());
Back then it worked out of Netbeans and from the jar-file.
Now I have to come back to this project and suddenly the jar no longer uses a relative path:
java.io.FileNotFoundException: C:\Users\Dromlius\.\cache\consoleBG.png
I tried everything and the solution I found online:
MyClass.class.getResource("cache/consoleBG.png").toUri()
results in a NullPointerException!
I just need a quick and dirty way to get the relative path to the .jar-file, because the software will be used on many different systems.
Thank you in advance,
Dromlius
EDIT: Ok, when I call the jar from console like:
C:\Users\Dromlius>java -jar X:\Dromlius\Projects\MyProgram.jar
it does not work!
But if I navigate to the folder X:\Dromlius\Projects
first, it works.i
I don't know why, but it is enough for my purpose.
I'm going to leave this question open for a bit though because someone might have similar problems and can not use this workaround.