Unable to locate the resource using classloader

hello all

i have cerated a simple web app with following structure.

-index.jsp

-WEB-INF

- lib

- cltest.jar

- web.xml

here

cltest.jar contains a class test.example.CLtest and my.prop file.

code of this class is

package test.example;

publicclass CLtest

{

static

{

System.out.println("Classloader -- " + CLtest.class.getClassLoader());

System.out.println("Resource -- "

+ CLtest.class.getClassLoader().getResourceAsStream(

"test/example/my.prop"));

}

}

also in my index.jsp i have

<%@ page import="test.example.CLtest" %>

<%

Class c= CLtest.class;

%>

Now

when i run the index.jsp in jboss server. i m not able to locate my.prop resource using

CLtest.class.getClassLoader().getResourceAsStream("/test/example/my.prop")

but

i amd able to locate it using

CLtest.class.getClassLoader().getResourceAsStream("test/example/my.prop")

So my question is whats the difference between

CLtest.class.getClassLoader().getResourceAsStream("/test/example/my.prop")

and

CLtest.class.getClassLoader().getResourceAsStream("test/example/my.prop")

thanks in advance

[1615 byte] By [preetam_picta] at [2007-11-27 11:36:32]
# 1

I don't see any difference between the four examples you posted at the end so I wonder if you got carried away with the copy and paste there.

Class loading in JBoss is buggy. This is due to shoddy JBoss-nesses though they keep trying to blame Sun. Funny though that nobody else has this problem...

cotton.ma at 2007-7-29 17:09:19 > top of Java-index,Java Essentials,Java Programming...
# 2

thanks cotton.m

No just observe the difference of "/" in resource name

CLtest.class.getClassLoader().getResourceAsStream("/test/example/my.prop")

and

CLtest.class.getClassLoader().getResourceAsStream("test/example/my.prop")

so you want to to try this in other app server ?

preetam_picta at 2007-7-29 17:09:19 > top of Java-index,Java Essentials,Java Programming...
# 3

> I don't see any difference between the four examples

> you posted at the end so I wonder if you got carried

> away with the copy and paste there.

Note the leading slash.

Your properties are inside the /test/examples "folder" in the JAR or accidentally somewhere else? Can you verify that?

CeciNEstPasUnProgrammeura at 2007-7-29 17:09:19 > top of Java-index,Java Essentials,Java Programming...
# 4

> thanks cotton.m

>

> No just observe the difference of "/" in resource

> name

>

Sorry. I looked and looked but I did not see that. I figure there was an extra or missing / somewhere but I didn't see it. :(

I think I need to go to the eye-doctor.

cotton.ma at 2007-7-29 17:09:19 > top of Java-index,Java Essentials,Java Programming...
# 5

> Your properties are inside the /test/examples

> "folder" in the JAR or accidentally somewhere else?

> Can you verify that?

Yes the properties file is in "/test/examples" "folder".

preetam_picta at 2007-7-29 17:09:19 > top of Java-index,Java Essentials,Java Programming...