I am confused about how java load's it's files.
public static File loadFile(String file) throws IOException {
URL url = ClassLoader.getSystemClassLoader().getResource(file);
if(url == null){
throw new IOException("Cannot find: " + file);
}
File ret;
try {
ret = new File(url.toURI());
return ret;
} catch (URISyntaxException e) {
System.err.println("URISyntaxException in Utility.loadFile(): Tried to load: "+ file);
throw new IOException("Cannot load: " + file);
}
}
Here is an (edited) image of the project stucture in Eclipse, where loading the resource works just fine ...
When loading the resouce, I call the above method like this:
char sep = File.seperatorChar;
File file = Utility.loadFile(sep + "res" + sep + "shader"
+ sep + "some_shader.glsl");
Though - here is what the .jar looks like (also edited)
As soon as I run the jar with java -jar prog.jar , I get:
java.io.IOException: Cannot find: \res\shader\some_shader.glsl
I do not want to use any "relative" path to any kind of class, I always want to use the "absolute" path to the resource from the root of my project's structure (from .../src/... or from ... .jar!/...)