RE: 3.3 classloading resources
Hi Costin, Yes, I verified that this does indeed do the trick. Wonder if Sun is going to fix ResourceBundle to handle this? Hope so! At any rate, thanks for the tip. Keith | -Original Message- | From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] | Sent: Monday, November 26, 2001 6:49 PM | To: Tomcat Developers List | Subject: Re: 3.3 classloading resources | | | The solution - for JDK1.2+ - is to use the 3 parameter getBundle, with | Thread.currentThread().getContextClassLoader() as the third param. | For JDK1.1 there's nothing you can do. | | Let me know if it doesn't work - I tried this before and I had no | problems. The resources could be in WEB-INF/classes, a jar in | WEB-INF/lib or any jar in the app.classloader. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: 3.3 classloading resources
I could be being naive on this one, but I've always loaded property files and other resources by putting them in the WEB-INF/classes directory of my class path, then doing something like: InputStream istr=getClass().getResourceAsStream(/myprops.properties); Properties props=new Properties(); props.load(istr); istr.close(); You have to make sure that the above snippet of code is in a non-static context and inside of a class that is either in a jar file in the WEB-INF/lib directory or in the WEB-INF/classes directory. I've tested the above approach in tomcat 3.2.x and in IBM WebSphere 3.5.4 and it has worked in both. I hope this has helped. -Mike - Original Message - From: Keith Wannamaker [EMAIL PROTECTED] To: Tomcat Developers List [EMAIL PROTECTED] Sent: Monday, November 26, 2001 2:44 PM Subject: 3.3 classloading resources I think there may be a problem with resource loading in TC3.3. If I add a property file to the app class path by setting org.apache.tomcat.apps.classpath, then the call to ResourceBundle.getBundle(foo) doesn't find it. Nor does it get located if I place the said property file in tomcat/lib/apps. In fact, the only way I have been able to find it is to override the classpath in the tomcat script. The good news is that, by setting org.apache.tomcat.apps.classpath, initClassLoaders() does set the AppsLoader class to a ClassLoader which contains my properties file. The bad news is this doesn't seem to be the deafult loader used in the call to ResourceBundle.getBundle(foo). The only thing I can think of trying is ResourceBundle.getBundle(foo, Locale.getDefault(), magic.ContextManager.getAppsLoader()); but that binds the code to the Tomcat container. My next step is to rebuild the jdk with debugging info to see which loader is actually being used in ResourceBundle.getBundle, but I appreciate any insight in the interim. Keith -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: 3.3 classloading resources
The problem is that ResourceBundle is kindof broken. Like many other java APIs ( JAXP, JNDI, URL, etc ), early versions are not capable of using the application class loader. This is ( IMHO ) a bug, and for some APIs it is fixed ( JAXP and JNDI for sure, unfortunately not for URL ). The solution - for JDK1.2+ - is to use the 3 parameter getBundle, with Thread.currentThread().getContextClassLoader() as the third param. For JDK1.1 there's nothing you can do. Let me know if it doesn't work - I tried this before and I had no problems. The resources could be in WEB-INF/classes, a jar in WEB-INF/lib or any jar in the app.classloader. Costin On Mon, 26 Nov 2001, Keith Wannamaker wrote: I think there may be a problem with resource loading in TC3.3. If I add a property file to the app class path by setting org.apache.tomcat.apps.classpath, then the call to ResourceBundle.getBundle(foo) doesn't find it. Nor does it get located if I place the said property file in tomcat/lib/apps. In fact, the only way I have been able to find it is to override the classpath in the tomcat script. The good news is that, by setting org.apache.tomcat.apps.classpath, initClassLoaders() does set the AppsLoader class to a ClassLoader which contains my properties file. The bad news is this doesn't seem to be the deafult loader used in the call to ResourceBundle.getBundle(foo). The only thing I can think of trying is ResourceBundle.getBundle(foo, Locale.getDefault(), magic.ContextManager.getAppsLoader()); but that binds the code to the Tomcat container. My next step is to rebuild the jdk with debugging info to see which loader is actually being used in ResourceBundle.getBundle, but I appreciate any insight in the interim. Keith -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]