Hi, this is really a user question, but I'll answer it here.
[EMAIL PROTECTED] wrote:
Hello,
I need help with a classloader problem. Can someone tell me the difference
between:
String s = "/data/demo.txt";
URL u1 = this.getClass().getResource(s);
URL u2 = this.getClass().getClassLoader().getResource(s);
My problem: u1 is != null (so the path is correct and the resouce is in
the JAR, etc) but u2 is *always* null.
Correct, see the javadoc for java.lang.Class.getResource and
java.lang.ClassLoader.getResource.
getClass().getResource("/x") is the same as
getClass().getClassLoader().getResource("x");
getClass().getResource("x") is the same as getClass().getClassLoader().getResource(
getClass().getPackage().getName().replace(".", "/") + "/" + "x");
So in your case, getClass().getResource() _should_ have the leading /, but for
u2 you should NOT use the leading /.
-- Kenney
I've been looking at the Java VM source (Sun) and getResource() just calls
getClassLoader0() just like getClassLoader() does (there is no
SecurityManager installed).
Regards,
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]