tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wade Chandler <wchand...@redesetgrow.com>
Subject Re: Classloading issue
Date Thu, 09 Dec 2004 22:02:19 GMT
Yu, John wrote:
> Wade,
> 
> Thanks for sharing. When you say using package, you mean
> for resource files?
> 
> One specific thing you didn't mention is where the calling
> class is located. In my case, it's a class from within a 
> jar in "lib". That really made the difference. My 
> conclusion so far is similar: when using "/", CL could
> make a big difference. Better stay away from it?
> 
> Regards,
> John
> 
> 
>>-----Original Message-----
>>From: Wade Chandler [mailto:wchandler@redesetgrow.com]
>>Sent: Thursday, December 09, 2004 4:31 PM
>>To: Tomcat Users List
>>Subject: Re: Classloading issue
>>
>>
>>Yu, John wrote:
>>
>>>Hi,
>>>
>>>I'm using Struts plugin, however, I think the issue mostly 
>>
>>related to Tomcat
>>
>>>ClassLoading.
>>>
>>>I have a class (in a jar) under WEB-INF/lib, which loads 
>>
>>properties from 
>>
>>>a file located under WEB-INF/classes. 
>>>
>>>     ClassLoader cl = getClass().getClassLoader();
>>>     InputStream stream = 
>>
>>cl.getResourceAsStream("plugin.properties");
>>
>>>I have tried different versions of path, with the results I 
>>
>>couldn't totally
>>
>>>explain:
>>>1. "plugin.properties": not work
>>>2. "WEB-INF/classes/plugin.properties": work
>>>3. "/WEB-INF/classes/plugin.properties": not work
>>>4. "/plugin.properties": not work
>>>
>>>Also, I'm using Tomcat 4.0.6 (NB3.5.1). Does anyone have an answer
>>>for this? Is "/" bad? It may apply to Tomcat 5 as well, isn't it?
>>>
>>>Regards,
>>>John
>>>
>>>
>>>
>>>
>>>The contents of this e-mail are intended for the named 
>>
>>addressee only. It
>>
>>>contains information that may be confidential. Unless you 
>>
>>are the named
>>
>>>addressee or an authorized designee, you may not copy or 
>>
>>use it, or disclose
>>
>>>it to anyone else. If you received it in error please 
>>
>>notify us immediately
>>
>>>and then destroy it. 
>>>
>>>
>>>
>>
>>---------------------------------------------------------------------
>>
>>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>>Me and another gentleman had this conversation just a little while 
>>ago...well one similar to it.  I always have a package which I put my 
>>files in.  I never have a problem doing that.  I always use 
>>Class.class.getResourceAsStream and getResource (should be 
>>roughly the 
>>same...usage is a little different).  I have a web app that 
>>has multiple 
>>installations on the same server and they always find their 
>>files.  But, 
>>I always use a package so I can access the files that way.  I 
>>quit using 
>>an empty package for everything when I started having goofy problems 
>>with different app servers.  I run into the same thing on 
>>Oracle 9iAS once.
>>
>>"/plugin.properties"
>>and
>>"plugin.properties"
>>
>>Are very different when you are using 
>>ClassLoader.getResource(AsStream), 
>>and the same thing applies to Class.getResource(AsString)...see java 
>>docs.  Again, I never have a problem, and I load property files from 
>>under the classes directory all the time.
>>
>>Wade
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
> 
> 
> 
> 
> The contents of this e-mail are intended for the named addressee only. It
> contains information that may be confidential. Unless you are the named
> addressee or an authorized designee, you may not copy or use it, or disclose
> it to anyone else. If you received it in error please notify us immediately
> and then destroy it. 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 

Using the / on the classloader call will be like trying to access a file 
on your root drive or your / directory on *nix.  But yes, I usually put 
my properties files in a folder under classes and access them that way 
just like accessing a file on the classpath...even though they are 
files.  Under classes I'll have a com/redesetgrow directory and I'll put 
config files in there.

Yes I use a class from one of my packages that I know will only be with 
my webapp.  I always use the full classpath path to the resource and use 
a class instead of a ClassLoader.  I always do 
com.redesetgrow.util.io.IO.class.getResource("/com/redesetgrow/config.properties");
or
com.redesetgrow.util.io.IO.class.getResourceAsStream("/com/redesetgrow/config.properties");

I always use that full path because a certain vm had a weird bug that 
bit me before (java 1.3 on IBM AIX using Oracle 9iAS got me like that 
one time).  So I used the full path thing and the class call and that 
did the trick for me.  Since then just out of habit I use that call, and 
the full path, and I never have problems.  I figure it helps me not 
forget anything, plus I just use one method of getting resources on the 
classpath.  To me it's more readable now.  Using the / at the front 
tells that call to not replace the slashes with .'s when it goes to find 
my file.  Not putting the / in the front would make the call replace all 
the / with .'s.  Another cool thing about that is I have one resource 
class I use for looking up everything since I use the full "classpath" 
to the resource.  Though it won't work well for relative paths.

My favorite part is: "I never have a problem with it."  :-)

Wade


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message