You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Oikonomopoulos Spyros <ik...@aegean.gr> on 2003/05/07 14:58:19 UTC

getResourceAsStream - Again

Hi to all,

I have spent some time reading previous posts about this issue, but haven't
found anything really helpful. If somebody has found a solution, please
share it...

I have a simple java class that tries to read a .properties file:

InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("LDAP.properties");

And make a simple jws file from it which is deployed by axis perfectly. The
bad news is that I always get null for the ini_stream. I have put the
LDAP.properties file in:
	- axis/web-inf
	- axis/web-inf/jwsClasses
	- axis/web-inf/classes
	- axis/web-inf/lib
	- axis/

and to any other possible directory, including tomcat's structure' Have also
tried:

InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("/LDAP.properties");
InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("web-inf/LDAP.properties");
InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("/web-inf/LDAP.properties");

But still nothing happens; The interesting(?) thing is that if I try to get
the ini_stream from another class that this one calls, it works fine (as
long as the LDAP.properties is in the
web-inf/classes/packageOfTheSecondClass/ directory)

Please provide any suggestions

Oikonomopoulos Spyros
SW Engineer
Greece


RE: getResourceAsStream - Again

Posted by Oikonomopoulos Spyros <ik...@aegean.gr>.
It worked perfectly with the wsdd file!!!! It seems that somebody in the dev
team does not like .jws files  :)

Thanks again

Spyros

-----Original Message-----
From: Brian Ewins [mailto:Brian.Ewins@btinternet.com]
Sent: Wednesday, May 07, 2003 4:40 PM
To: axis-user@ws.apache.org
Subject: Re: getResourceAsStream - Again


first off, do you have the case right? It should be WEB-INF not web-inf.
These combinations should work, for com.something.NameServerWebService:

axis/WEB-INF/classes/LDAP.properties
InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("/LDAP.properties");
OR
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/classes/LDAP.properties"));

axis/WEB-INF/classes/com/something/LDAP.properties
InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("LDAP.properties");
OR
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/classes/com/something/LDAP.prop
erties"));

axis/WEB-INF/LDAP.properties
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/LDAP.properties"));

The servletContext version is immune to classloader issues. The others
only search within the classloader hierarchy from the class you started
at, so you need to be sure the class you're using is from the Webapp
classloader, not the shared, common, bootstrap, ... etc classloaders.

Incidentally, the servletContext.getResourceAsStream may well treat
WEB-INF case-insensitively (because of servlet spec sect 9.5 - its
ambiguous on this point), but the class.getResourceAsStream versions are
case-sensitive and will not find 'web-inf' when you mean 'WEB-INF'.

Hope this helps.
	Baz

Oikonomopoulos Spyros wrote:

> Hi to all,
>
> I have spent some time reading previous posts about this issue, but
haven't
> found anything really helpful. If somebody has found a solution, please
> share it...
>
> I have a simple java class that tries to read a .properties file:
>
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("LDAP.properties");
>
> And make a simple jws file from it which is deployed by axis perfectly.
The
> bad news is that I always get null for the ini_stream. I have put the
> LDAP.properties file in:
> 	- axis/web-inf
> 	- axis/web-inf/jwsClasses
> 	- axis/web-inf/classes
> 	- axis/web-inf/lib
> 	- axis/
>
> and to any other possible directory, including tomcat's structure' Have
also
> tried:
>
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("/LDAP.properties");
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("web-inf/LDAP.properties");
> InputStream ini_stream =
>
NameServerWebService.class.getResourceAsStream("/web-inf/LDAP.properties");
>
> But still nothing happens; The interesting(?) thing is that if I try to
get
> the ini_stream from another class that this one calls, it works fine (as
> long as the LDAP.properties is in the
> web-inf/classes/packageOfTheSecondClass/ directory)
>
> Please provide any suggestions
>
> Oikonomopoulos Spyros
> SW Engineer
> Greece
>
>


RE: getResourceAsStream - Again

Posted by Oikonomopoulos Spyros <ik...@aegean.gr>.
Unfortunately yes, the case is right in my code :) Now about the
"servletContext",  I really don't want to use it, cause the class is also
used in other contexts and I see no reason to change the code (if I can put
it to work, that is...)  ALL other combinations fail.....

Maybe it happens cause I am using the .jws auto deployment facility? I will
try to do it with a wsdd file and see what happens....

Thanks

Spyros



-----Original Message-----
From: Brian Ewins [mailto:Brian.Ewins@btinternet.com]
Sent: Wednesday, May 07, 2003 4:40 PM
To: axis-user@ws.apache.org
Subject: Re: getResourceAsStream - Again


first off, do you have the case right? It should be WEB-INF not web-inf.
These combinations should work, for com.something.NameServerWebService:

axis/WEB-INF/classes/LDAP.properties
InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("/LDAP.properties");
OR
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/classes/LDAP.properties"));

axis/WEB-INF/classes/com/something/LDAP.properties
InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("LDAP.properties");
OR
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/classes/com/something/LDAP.prop
erties"));

axis/WEB-INF/LDAP.properties
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/LDAP.properties"));

The servletContext version is immune to classloader issues. The others
only search within the classloader hierarchy from the class you started
at, so you need to be sure the class you're using is from the Webapp
classloader, not the shared, common, bootstrap, ... etc classloaders.

Incidentally, the servletContext.getResourceAsStream may well treat
WEB-INF case-insensitively (because of servlet spec sect 9.5 - its
ambiguous on this point), but the class.getResourceAsStream versions are
case-sensitive and will not find 'web-inf' when you mean 'WEB-INF'.

Hope this helps.
	Baz

Oikonomopoulos Spyros wrote:

> Hi to all,
>
> I have spent some time reading previous posts about this issue, but
haven't
> found anything really helpful. If somebody has found a solution, please
> share it...
>
> I have a simple java class that tries to read a .properties file:
>
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("LDAP.properties");
>
> And make a simple jws file from it which is deployed by axis perfectly.
The
> bad news is that I always get null for the ini_stream. I have put the
> LDAP.properties file in:
> 	- axis/web-inf
> 	- axis/web-inf/jwsClasses
> 	- axis/web-inf/classes
> 	- axis/web-inf/lib
> 	- axis/
>
> and to any other possible directory, including tomcat's structure' Have
also
> tried:
>
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("/LDAP.properties");
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("web-inf/LDAP.properties");
> InputStream ini_stream =
>
NameServerWebService.class.getResourceAsStream("/web-inf/LDAP.properties");
>
> But still nothing happens; The interesting(?) thing is that if I try to
get
> the ini_stream from another class that this one calls, it works fine (as
> long as the LDAP.properties is in the
> web-inf/classes/packageOfTheSecondClass/ directory)
>
> Please provide any suggestions
>
> Oikonomopoulos Spyros
> SW Engineer
> Greece
>
>


Re: getResourceAsStream - Again

Posted by Brian Ewins <Br...@btinternet.com>.
first off, do you have the case right? It should be WEB-INF not web-inf. 
These combinations should work, for com.something.NameServerWebService:

axis/WEB-INF/classes/LDAP.properties
InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("/LDAP.properties");
OR
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/classes/LDAP.properties"));

axis/WEB-INF/classes/com/something/LDAP.properties
InputStream ini_stream =
NameServerWebService.class.getResourceAsStream("LDAP.properties");
OR
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/classes/com/something/LDAP.properties"));

axis/WEB-INF/LDAP.properties
InputStream ini_stream =
servletContext.getResourceAsStream("/WEB-INF/LDAP.properties"));

The servletContext version is immune to classloader issues. The others 
only search within the classloader hierarchy from the class you started 
at, so you need to be sure the class you're using is from the Webapp 
classloader, not the shared, common, bootstrap, ... etc classloaders.

Incidentally, the servletContext.getResourceAsStream may well treat 
WEB-INF case-insensitively (because of servlet spec sect 9.5 - its 
ambiguous on this point), but the class.getResourceAsStream versions are 
case-sensitive and will not find 'web-inf' when you mean 'WEB-INF'.

Hope this helps.
	Baz

Oikonomopoulos Spyros wrote:

> Hi to all,
> 
> I have spent some time reading previous posts about this issue, but haven't
> found anything really helpful. If somebody has found a solution, please
> share it...
> 
> I have a simple java class that tries to read a .properties file:
> 
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("LDAP.properties");
> 
> And make a simple jws file from it which is deployed by axis perfectly. The
> bad news is that I always get null for the ini_stream. I have put the
> LDAP.properties file in:
> 	- axis/web-inf
> 	- axis/web-inf/jwsClasses
> 	- axis/web-inf/classes
> 	- axis/web-inf/lib
> 	- axis/
> 
> and to any other possible directory, including tomcat's structure' Have also
> tried:
> 
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("/LDAP.properties");
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("web-inf/LDAP.properties");
> InputStream ini_stream =
> NameServerWebService.class.getResourceAsStream("/web-inf/LDAP.properties");
> 
> But still nothing happens; The interesting(?) thing is that if I try to get
> the ini_stream from another class that this one calls, it works fine (as
> long as the LDAP.properties is in the
> web-inf/classes/packageOfTheSecondClass/ directory)
> 
> Please provide any suggestions
> 
> Oikonomopoulos Spyros
> SW Engineer
> Greece
> 
>