I’m setting up a dev environment and I have this bit of code bothering me:
public static URI getResource(Class<?> cl, String resource) {
URL url = cl.getResource(resource);
//etc...
}
Problem is: url is null. The ressource in question is a file located in the exact directory as the java file. And this is supposed to return a non null url.
This environment has been installed sucessfully by many people, but it does not work on my machine.
Additional info:
- getRessource() is supposed to use the classLoader of cl. (This classLoader).toString() gives: “sun.misc.Launcher$AppClassLoader@11b86e7”
- This code is in a jUnit test which I run through eclipse Indigo on Windows 7 (problem of different file context in linux/windows?)
The classloader is expecting to get the resource file from the same directory as the .class file, not the .java file. Depending on how your Eclipse project is configured, these may be different directories.
Normally, your build process will copy the resource file to the output directory as it creates the .class files, but in this case, maybe it didn’t?