-----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-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org