tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: [SOLVED]RE: getResourceAsStream cached by Tomcat'sClassloader?
Date Thu, 05 Jun 2003 20:08:32 GMT
Howdy,
Seeing your comment made me think twice, and then test it out... And I
was wrong!  The code below works even in a packed .war it seems.
(Tomcat 4.1.24, JDK 1.4.1, Solaris 8, autoDeploy="false",
unpackWARS="false", test.war attached).  Sorry about that -- my mistake.

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Larry Meadors [mailto:Larry.Meadors@plumcreek.com]
>Sent: Thursday, June 05, 2003 3:38 PM
>To: tomcat-user@jakarta.apache.org
>Subject: RE: [SOLVED]RE: getResourceAsStream cached by
Tomcat'sClassloader?
>
>Really? I guess I have seen enough right answers from you to not doubt
>it, but I thought that using the URL would work...
>
>Larry
>
>>>> Yoav.Shapira@mpi.com 06/05/03 12:37 PM >>>
>
>Howdy,
>Please note your approach will fail when running from a packed .war
>file, as the new File(..) will throw an exception.  This might be OK
for
>your environment, but is important to keep in mind for portability.
>
>Yoav Shapira
>Millennium ChemInformatics
>
>
>>-----Original Message-----
>>From: Brandon Goodin [mailto:mail@phase.ws]
>>Sent: Thursday, June 05, 2003 2:08 PM
>>To: Tomcat Users List
>>Subject: [SOLVED]RE: getResourceAsStream cached by Tomcat's
>Classloader?
>>
>>Well, here is how I solved my problem:
>>
>>-- code start --
>>
>>String resource = "my-config.xml";
>>
>>ClassLoader loader =
>>  Thread.currentThread().getContextClassLoader();
>>
>>URL url =
>>  loader.getResource(resource);
>>
>>Reader reader =
>>  new FileReader(
>>    new File(
>>      url.getFile()));
>>
>>-- code stop --
>>
>>Directly calling the getResourceAsStream failed to produce a copy of
>the
>>altered config. Is this a bug?
>>
>>Brandon Goodin
>>
>>-----Original Message-----
>>From: Brandon Goodin [mailto:mail@phase.ws]
>>Sent: Thursday, June 05, 2003 11:23 AM
>>To: Tomcat Users List
>>Subject: RE: getResourceAsStream cached by Tomcat's Classloader?
>>
>>
>>Aaaah. A man after my own heart! Keep it simple.
>>
>>Brandon Goodin
>>
>>-----Original Message-----
>>From: Larry Meadors [mailto:Larry.Meadors@plumcreek.com]
>>Sent: Thursday, June 05, 2003 11:12 AM
>>To: tomcat-user@jakarta.apache.org
>>Subject: RE: getResourceAsStream cached by Tomcat's Classloader?
>>
>>
>>I think you are right, but I always use Thread method because it works
>>even in a static method - you do not need 'this' for it to work.
>>
>>I prefer having one way to do this instead of two - that way I can
>think
>>less about how to get the CL, and more about the problem it will help
>me
>>solve (and I am lazy). ;-)
>>
>>Larry
>>
>>>>> mail@phase.ws 06/05/03 10:58 AM >>>
>>>"Are you using this code to get a classloader?
>>>Thread.currentThread().getContextClassLoader();
>>>If not, you are not getting tomcat's you are getting the system one."
>>
>>Are you sure this is true?
>>
>>A ClassLoader can have a parent ClassLoader. But, a class does not
>>maintain
>>a single copy across all ClassLoader contexts. Therefore, the Class
>type
>>can
>>exist in multiple ClassLoaders. So a Class has a reference to it's
>>ClassLoader context when it is created. When the
>>this.getClass().getClassLoader() is called it calls the context that
>the
>>class was loaded in. I think you would have to specifically call the
>>getParent() of the Classloader in order to go up the Classloader
chain.
>>In
>>this situation I think Thread.currentThread().getContextClassLoader()
>>and
>>this.getClass().getClassLoader() will accomplish the same thing.
>>
>>Brandon Goodin
>>
>>-----Original Message-----
>>From: Larry Meadors [mailto:Larry.Meadors@plumcreek.com]
>>Sent: Thursday, June 05, 2003 9:45 AM
>>To: tomcat-user@jakarta.apache.org
>>Subject: RE: getResourceAsStream cached by Tomcat's Classloader?
>>
>>
>>Are the static variables transient? If not, the session manager may
>>persist them on a reload.
>>
>>>>> mail@phase.ws 06/05/03 9:41 AM >>>
>>I have tried it both ways. My notion is that it has to do with the
fact
>>that
>>the getResourceAsStream is being called in a static method and the
>>resulting
>>InputStream, which is wrapped in an InputStreamReader, is passed into
>an
>>object that is a static variable in my BaseDAO class. So, because the
>>reference is at the Class level it might be holding onto it no matter
>>what I
>>do. If you want I can show you the code. I have some ideas. But, I'm
>not
>>sure if they will work.
>>
>>Brandon Goodin
>>
>>-----Original Message-----
>>From: Larry Meadors [mailto:Larry.Meadors@plumcreek.com]
>>Sent: Thursday, June 05, 2003 8:58 AM
>>To: tomcat-user@jakarta.apache.org
>>Cc: mail@phase.ws
>>Subject: RE: getResourceAsStream cached by Tomcat's Classloader?
>>
>>
>>Hey Brandon,
>>
>>Are you using this code to get a classloader?
>>
>>Thread.currentThread().getContextClassLoader();
>>
>>If not, you are not getting tomcat's you are getting the system one.
>>
>>Larry
>>
>>>>> mail@phase.ws 06/05/03 8:04 AM >>>
>>Yes, it is closed.
>>
>>Brandon Goodin
>>
>>-----Original Message-----
>>From: Dominic Parry [mailto:dom@rucus.ru.ac.za]
>>Sent: Thursday, June 05, 2003 7:44 AM
>>To: Tomcat Users List
>>Subject: Re: getResourceAsStream cached by Tomcat's Classloader?
>>
>>
>>did you close the original stream before making changes and reloading?
>>
>>
>>----- Original Message -----
>>From: "Brandon Goodin" <mail@phase.ws>
>>To: <tomcat-user@jakarta.apache.org>
>>Sent: Thursday, June 05, 2003 3:45 PM
>>Subject: getResourceAsStream cached by Tomcat's Classloader?
>>
>>
>>> I saw a question similar to this asked in the Archives early in
2002.
>>I
>>> didn't see a response to it. So, I hope there is an answer.
>>>
>>> I have a generic config file that is an xml file. We'll call it
>>> my-config.xml.
>>>
>>> When I load my-config.xml using
>>> Classloader.getResourceAsStream("my-config.xml") everything works
>>great.
>>> However, when I make a change to that file and again call
>>> Classloader.getResourceAsStream("my-config.xml") the changes are not
>>picked
>>> up and the same initial resource is returned. How do I get the
>>Classloader
>>> to reconginze the resource changes? I'm using Tomcat 4.1.18.
>>>
>>>
>>> Brandon Goodin
>>>
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
>This e-mail, including any attachments, is a confidential business
>communication, and may contain information that is confidential,
>proprietary and/or privileged.  This e-mail is intended only for the
>individual(s) to whom it is addressed, and may not be saved, copied,
>printed, disclosed or used by anyone else.  If you are not the(an)
>intended recipient, please immediately delete this e-mail from your
>computer system and notify the sender.  Thank you.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.



Mime
View raw message