You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Guimaraes, Patricia (NIH/NLM) [C]" <pg...@mail.nlm.nih.gov> on 2009/05/22 20:29:02 UTC

different behavior in processing jar files in Tomcat 5.0.28 and Tomcat 6.0.18

Hi,

In the process of migrating an application from Tomcat 5.0.28 to Tomcat 6.0.18, I've identified a different behavior in processing jar files between the two versions.  I've attached a small test application (testapp.war) that can be run under both versions to display the differences.  I've also included the appropriate lines from the log files of the two versions below.

Essentially, when running my Java code which calls method getResource(String name) of class Class to find a resource that is part of a jar file, Tomcat 5.0.28 finds the jar file in the classpath and expands it in directory jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader.  And then I can access the resource in the expanded jar file by calling the getPath() method on the instance of the URL class returned by the getResource(String name) method.

However, when running the same code with Tomcat 6.0.18, Tomcat finds the resource in the jar file, but it does not expand the jar file under the apache-tomcat-6.0.18/work/Catalina/localhost directory tree and therefore, I cannot access the resource from the jar file.

I've checked the Servlet Specification Version 2.4 (Tomcat 5) and Version 2.5 (Tomcat 6) to see if this should be the expected behavior under Tomcat 6, but as far as I can tell, it should process jar files in the same was as Tomcat 5.

If anyone can let me know what the correct behavior should be for Tomcat 6, and if there is a way that I can force Tomcat 6 to process jar files in the same way as Tomcat 5, I would greatly appreciate it.

Thanks,

Pat



Tomcat 5.0.28:
-------------

~/opt/jakarta-tomcat-5.0.28/logs % cat ~/opt/jakarta-tomcat-5.0.28/logs/catalina.out | fgrep StartupServlet
2009-05-22_11:56 StartupServlet_init - Initializing servlet StartupServlet
2009-05-22_11:56 StartupServlet_init - url = file:/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/
2009-05-22_11:56 StartupServlet_init - url.getPath() = /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/
2009-05-22_11:56 StartupServlet_init - url.getFile() = /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/
2009-05-22_11:56 StartupServlet_init - url.getProtocol() = file
2009-05-22_11:56 StartupServlet_processPath - pathName = /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/
2009-05-22_11:56 StartupServlet_processPath - fileName = queryDefns
2009-05-22_11:56 StartupServlet_processPath - File queryDefns exists.
2009-05-22_11:56 StartupServlet_processPath - pathName = /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/describeRawTables.xml
2009-05-22_11:56 StartupServlet_processPath - fileName = describeRawTables.xml
2009-05-22_11:56 StartupServlet_processPath - File describeRawTables.xml exists.
2009-05-22_11:56 StartupServlet_processFile - File describeRawTables.xml is a file.
~/opt/jakarta-tomcat-5.0.28/logs %
~/opt/jakarta-tomcat-5.0.28/logs %
~/opt/jakarta-tomcat-5.0.28/logs % find /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/tldCache.ser
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/META-INF
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/META-INF/MANIFEST.MF
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/describeRawTables.xml
~/opt/jakarta-tomcat-5.0.28/logs %


Tomcat 6.0.18:
-------------

~/apps/apache-tomcat-6.0.18/logs % cat ~/apps/apache-tomcat-6.0.18/log/catalina.out | fgrep StartupServlet
2009-05-22_12:27 StartupServlet_init - Initializing servlet StartupServlet
2009-05-22_12:27 StartupServlet_init - url = jar:file:/usr/nlm/kss/apps/apache-tomcat-6.0.18/webapps/testapp/WEB-INF/lib/sample.jar!/queryDefns
2009-05-22_12:27 StartupServlet_init - url.getPath() = file:/usr/nlm/kss/apps/apache-tomcat-6.0.18/webapps/testapp/WEB-INF/lib/sample.jar!/queryDefns
2009-05-22_12:27 StartupServlet_init - url.getFile() = file:/usr/nlm/kss/apps/apache-tomcat-6.0.18/webapps/testapp/WEB-INF/lib/sample.jar!/queryDefns
2009-05-22_12:27 StartupServlet_init - url.getProtocol() = jar
2009-05-22_12:27 StartupServlet_processPath - pathName = file:/usr/nlm/kss/apps/apache-tomcat-6.0.18/webapps/testapp/WEB-INF/lib/sample.jar!/queryDefns
2009-05-22_12:27 StartupServlet_processPath - fileName = queryDefns
2009-05-22_12:27 StartupServlet_processPath - File queryDefns DOES NOT exist.
~/apps/apache-tomcat-6.0.18/logs %
~/apps/apache-tomcat-6.0.18/logs %
~/apps/apache-tomcat-6.0.18/logs % find ../work/
../work/
../work/Catalina
../work/Catalina/localhost
../work/Catalina/localhost/UMLS08AB
../work/Catalina/localhost/UMLS08AB/SESSIONS.ser
../work/Catalina/localhost/manager
../work/Catalina/localhost/manager/org
../work/Catalina/localhost/manager/org/apache
../work/Catalina/localhost/manager/org/apache/jsp
../work/Catalina/localhost/manager/org/apache/jsp/_401_jsp.java
../work/Catalina/localhost/manager/org/apache/jsp/_401_jsp.class
../work/Catalina/localhost/manager/SESSIONS.ser
../work/Catalina/localhost/host-manager
../work/Catalina/localhost/host-manager/SESSIONS.ser
../work/Catalina/localhost/RegService
../work/Catalina/localhost/RegService/SESSIONS.ser
../work/Catalina/localhost/testapp
~/apps/apache-tomcat-6.0.18/logs %




Patricia T. Guimaraes
NIH/NLM/OCCS/MLB
SCI Contractor
E-mail: pguimaraes@nlm.nih.gov
Phone:  301-496-3615
Building 38A, Room 2N-218




RE: different behavior in processing jar files in Tomcat 5.0.28 and Tomcat 6.0.18

Posted by Martin Gainty <mg...@hotmail.com>.
 
                Note that the explosion will not occur if the Host is configured 
                so that .WARs are not exploded with a unpackWARs
                attribute set to "false" to appBase which is usually webapps, the web application 
                will be simply redeployed as a compressed archive.
            

n
unpackWARs



          Should we unpack WAR files when auto-deploying applications in the
 appBase directory?
http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/startup/HostConfig.html
http://www.scribd.com/doc/7430501/Tomcat-War-Deployment

?
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




From: pguimaraes@mail.nlm.nih.gov
To: users@tomcat.apache.org
Date: Fri, 22 May 2009 14:29:02 -0400
Subject: different behavior in processing jar files in Tomcat 5.0.28 and Tomcat 6.0.18












Hi,
 
In the process of migrating an application from Tomcat 5.0.28 to Tomcat 6.0.18, I’ve identified a different behavior in processing jar files between the two versions.  I’ve attached a small test application (testapp.war) that can be run under both versions
to display the differences.  I’ve also included the appropriate lines from the log files of the two versions below.
 
Essentially, when running my Java code which calls method getResource(String name) of class Class to find a resource that is part of a jar file, Tomcat 5.0.28 finds the jar file in the classpath and expands it in directory jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader. 
And then I can access the resource in the expanded jar file by calling the getPath() method on the instance of the URL class returned by the getResource(String name) method.
 
However, when running the same code with Tomcat 6.0.18, Tomcat finds the resource in the jar file, but it does not expand the jar file under the apache-tomcat-6.0.18/work/Catalina/localhost directory tree and therefore, I cannot access the resource from
the jar file.
 
I’ve checked the Servlet Specification Version 2.4 (Tomcat 5) and Version 2.5 (Tomcat 6) to see if this should be the expected behavior under Tomcat 6, but as far as I can tell, it should process jar files in the same was as Tomcat 5.
 
If anyone can let me know what the correct behavior should be for Tomcat 6, and if there is a way that I can force Tomcat 6 to process jar files in the same way as Tomcat 5, I would greatly appreciate it.
 
Thanks,
 
Pat
 
 
 
Tomcat 5.0.28:
-------------
 
~/opt/jakarta-tomcat-5.0.28/logs % cat ~/opt/jakarta-tomcat-5.0.28/logs/catalina.out | fgrep StartupServlet
2009-05-22_11:56 StartupServlet_init - Initializing servlet StartupServlet
2009-05-22_11:56 StartupServlet_init - url = file:/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/
2009-05-22_11:56 StartupServlet_init - url.getPath() = /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/
2009-05-22_11:56 StartupServlet_init - url.getFile() = /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/
2009-05-22_11:56 StartupServlet_init - url.getProtocol() = file
2009-05-22_11:56 StartupServlet_processPath - pathName = /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/
2009-05-22_11:56 StartupServlet_processPath - fileName = queryDefns
2009-05-22_11:56 StartupServlet_processPath - File queryDefns exists.
2009-05-22_11:56 StartupServlet_processPath - pathName = /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/describeRawTables.xml
2009-05-22_11:56 StartupServlet_processPath - fileName = describeRawTables.xml
2009-05-22_11:56 StartupServlet_processPath - File describeRawTables.xml exists.
2009-05-22_11:56 StartupServlet_processFile - File describeRawTables.xml is a file.
~/opt/jakarta-tomcat-5.0.28/logs %
~/opt/jakarta-tomcat-5.0.28/logs %
~/opt/jakarta-tomcat-5.0.28/logs % find /usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/tldCache.ser
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/META-INF
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/META-INF/MANIFEST.MF
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns
/usr/nlm/kss/opt/jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader/queryDefns/describeRawTables.xml
~/opt/jakarta-tomcat-5.0.28/logs %
 
 
Tomcat 6.0.18:
-------------
 
~/apps/apache-tomcat-6.0.18/logs % cat ~/apps/apache-tomcat-6.0.18/log/catalina.out | fgrep StartupServlet
2009-05-22_12:27 StartupServlet_init - Initializing servlet StartupServlet
2009-05-22_12:27 StartupServlet_init - url = jar:file:/usr/nlm/kss/apps/apache-tomcat-6.0.18/webapps/testapp/WEB-INF/lib/sample.jar!/queryDefns
2009-05-22_12:27 StartupServlet_init - url.getPath() = file:/usr/nlm/kss/apps/apache-tomcat-6.0.18/webapps/testapp/WEB-INF/lib/sample.jar!/queryDefns
2009-05-22_12:27 StartupServlet_init - url.getFile() = file:/usr/nlm/kss/apps/apache-tomcat-6.0.18/webapps/testapp/WEB-INF/lib/sample.jar!/queryDefns
2009-05-22_12:27 StartupServlet_init - url.getProtocol() = jar
2009-05-22_12:27 StartupServlet_processPath - pathName = file:/usr/nlm/kss/apps/apache-tomcat-6.0.18/webapps/testapp/WEB-INF/lib/sample.jar!/queryDefns
2009-05-22_12:27 StartupServlet_processPath - fileName = queryDefns
2009-05-22_12:27 StartupServlet_processPath - File queryDefns DOES NOT exist.
~/apps/apache-tomcat-6.0.18/logs %
~/apps/apache-tomcat-6.0.18/logs %
~/apps/apache-tomcat-6.0.18/logs % find ../work/
../work/
../work/Catalina
../work/Catalina/localhost
../work/Catalina/localhost/UMLS08AB
../work/Catalina/localhost/UMLS08AB/SESSIONS.ser
../work/Catalina/localhost/manager
../work/Catalina/localhost/manager/org
../work/Catalina/localhost/manager/org/apache
../work/Catalina/localhost/manager/org/apache/jsp
../work/Catalina/localhost/manager/org/apache/jsp/_401_jsp.java
../work/Catalina/localhost/manager/org/apache/jsp/_401_jsp.class
../work/Catalina/localhost/manager/SESSIONS.ser
../work/Catalina/localhost/host-manager
../work/Catalina/localhost/host-manager/SESSIONS.ser
../work/Catalina/localhost/RegService
../work/Catalina/localhost/RegService/SESSIONS.ser
../work/Catalina/localhost/testapp
~/apps/apache-tomcat-6.0.18/logs %
 
 
 
 
Patricia T. Guimaraes
NIH/NLM/OCCS/MLB
SCI Contractor
E-mail: pguimaraes@nlm.nih.gov
Phone:  301-496-3615
Building 38A, Room 2N-218
 
 
 

_________________________________________________________________
Hotmail® has ever-growing storage! Don’t worry about storage limits.
http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage1_052009

RE: different behavior in processing jar files in Tomcat 5.0.28 andTomcat 6.0.18

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Guimaraes, Patricia (NIH/NLM) [C]
> [mailto:pguimaraes@mail.nlm.nih.gov]
> Subject: different behavior in processing jar files in Tomcat 5.0.28
> andTomcat 6.0.18
> 
> Essentially, when running my Java code which calls method
> getResource(String name) of class Class to find a resource
> that is part of a jar file, Tomcat 5.0.28 finds the jar
> file in the classpath and expands it in directory jakarta-tomcat-
> 5.0.28/work/Catalina/localhost/testapp/loader.

That's convenience behavior of the container, not defined by the spec.

> And then I can access the resource in the expanded jar file 
> by calling the getPath() method on the instance of the URL 
> class returned by the getResource(String name) method.

The container (Tomcat) is under no obligation to provide any access to the underlying file system (if there is one), other than temporary scratch space.  Your use of URL.getPath() - presumably followed by some variation of new File(path) - is risky, and was never guaranteed to work.

You should probably be using Class.getResourceAsStream(), which should function properly on any container.

- Chuck

P.S. Ignore Martin's response - it has no relevance to jars, just to .war files.


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


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


RE: different behavior in processing jar files in Tomcat 5.0.28 andTomcat 6.0.18

Posted by Martin Gainty <mg...@hotmail.com>.
Feel free to post the aberrant code as 90% of the folks on the list have coded at one time or another

HTH
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> From: pguimaraes@mail.nlm.nih.gov
> To: users@tomcat.apache.org
> Date: Fri, 22 May 2009 16:04:24 -0400
> Subject: RE: different behavior in processing jar files in Tomcat 5.0.28 andTomcat 6.0.18
> 
> Thank you all for your comments!  They were very helpful!
> 
> Unfortunately, the war file containing the test application was stripped from my original e-mail.
> 
> This is actually code that I inherited from someone else.  They were running it under Tomcat 5 and when I ran it under Tomcat 6, it didn't work the same way, which is why I started looking into this.  Also, the actual code is not in a servlet.  I just put it in a servlet in the test application so I could easily execute the same code when Tomcat was started.
> 
> Thanks again,
> 
> Pat
> 
> -----Original Message-----
> From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com] 
> Sent: Friday, May 22, 2009 3:34 PM
> To: Tomcat Users List
> Subject: RE: different behavior in processing jar files in Tomcat 5.0.28 andTomcat 6.0.18
> 
> > From: Christopher Schultz [mailto:chris@christopherschultz.net]
> > Subject: Re: different behavior in processing jar files in Tomcat
> > 5.0.28 andTomcat 6.0.18
> > 
> > On 5/22/2009 2:29 PM, Guimaraes, Patricia (NIH/NLM) [C] wrote:
> > > Essentially, when running my Java code which calls method
> > > getResource(String name) of class Class to find a resource 
> >
> > So, you're calling ServletContext.getResource(String)
> 
> No, Class.getResource() - the difference is significant.  I don't think ServletContext.getResource() will look inside .jar files.
> 
> The proper method is still getResourceAsStream(), but using the classloader or the class.
> 
>  - Chuck
> 
> 
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

_________________________________________________________________
Windows Live™: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_BR_life_in_synch_052009

RE: different behavior in processing jar files in Tomcat 5.0.28 andTomcat 6.0.18

Posted by "Guimaraes, Patricia (NIH/NLM) [C]" <pg...@mail.nlm.nih.gov>.
Thank you all for your comments!  They were very helpful!

Unfortunately, the war file containing the test application was stripped from my original e-mail.

This is actually code that I inherited from someone else.  They were running it under Tomcat 5 and when I ran it under Tomcat 6, it didn't work the same way, which is why I started looking into this.  Also, the actual code is not in a servlet.  I just put it in a servlet in the test application so I could easily execute the same code when Tomcat was started.

Thanks again,

Pat

-----Original Message-----
From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com] 
Sent: Friday, May 22, 2009 3:34 PM
To: Tomcat Users List
Subject: RE: different behavior in processing jar files in Tomcat 5.0.28 andTomcat 6.0.18

> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: different behavior in processing jar files in Tomcat
> 5.0.28 andTomcat 6.0.18
> 
> On 5/22/2009 2:29 PM, Guimaraes, Patricia (NIH/NLM) [C] wrote:
> > Essentially, when running my Java code which calls method
> > getResource(String name) of class Class to find a resource 
>
> So, you're calling ServletContext.getResource(String)

No, Class.getResource() - the difference is significant.  I don't think ServletContext.getResource() will look inside .jar files.

The proper method is still getResourceAsStream(), but using the classloader or the class.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

RE: different behavior in processing jar files in Tomcat 5.0.28 andTomcat 6.0.18

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: different behavior in processing jar files in Tomcat
> 5.0.28 andTomcat 6.0.18
> 
> On 5/22/2009 2:29 PM, Guimaraes, Patricia (NIH/NLM) [C] wrote:
> > Essentially, when running my Java code which calls method
> > getResource(String name) of class Class to find a resource 
>
> So, you're calling ServletContext.getResource(String)

No, Class.getResource() - the difference is significant.  I don't think ServletContext.getResource() will look inside .jar files.

The proper method is still getResourceAsStream(), but using the classloader or the class.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

Re: different behavior in processing jar files in Tomcat 5.0.28 and Tomcat 6.0.18

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Patricia,

On 5/22/2009 2:29 PM, Guimaraes, Patricia (NIH/NLM) [C] wrote:
> Essentially, when running my Java code which calls method
> getResource(String name) of class Class to find a resource that is part
> of a jar file, Tomcat 5.0.28 finds the jar file in the classpath and
> expands it in directory
> jakarta-tomcat-5.0.28/work/Catalina/localhost/testapp/loader.  And then
> I can access the resource in the expanded jar file by calling the
> getPath() method on the instance of the URL class returned by the
> getResource(String name) method.

So, you're calling ServletContext.getResource(String) (which returns a
URL) and then calling URL.getPath (which returns a String) and then
using /that/ to look on the filesystem? That is "not recommended technique".

> However, when running the same code with Tomcat 6.0.18, Tomcat finds the
> resource in the jar file, but it does not expand the jar file under the
> apache-tomcat-6.0.18/work/Catalina/localhost directory tree and
> therefore, I cannot access the resource from the jar file.

There is no guarantee made by the servlet specification that files will
be available on any kind of filesystem. No guarantee is made at all that
a filesystem will even exist!

If you want to load the contents of a file, why not call
ServletContext.getResourceAsStream(String) instead? You don't have to
mess around with URLs in that case, which is nice: you just get the
bytes you want.

> 2009-05-22_12:27 StartupServlet_init - Initializing servlet StartupServlet

Instead of using a StartupServlet, it's more appropriate to use a
ServletContextListener: the listener will be notified that the web
application has been started before any requests are accepted for
processing, and these listeners were explicitly designed for the purpose
you (likely) have here.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkoW/NMACgkQ9CaO5/Lv0PD+oACgpf5+2D/rlW/AJ6fW+8r/tThJ
UvgAoKudmJOeJ/MkXB1eW8D6W1frhXOZ
=HP4d
-----END PGP SIGNATURE-----

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