-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Chefo,
On 8/26/2010 9:38 AM, Chefo wrote: > I'm using tomcat 6.0.18 adapted to osgi environment and I would like to make > the WebappClassLoader configurable so that it does not load certain packages > directly through the system class loader but use the class loader hierarchy > instead. What ClassLoader hierarchy? > In order to do that I have extended the standard webapp class > loader and configured the container to use the new one in the base > context.xml. Ok. > I want to configure the packages through a context parameter > (separately for each webapp) or eventually through an env-entry. However I > cannot find a way to access the StandardContext instance in my > WebappClassLoader. That's because these two classes have no relationship to one another. > This is probably a very simple thing to do but I'm not > really well familiar with catalina API and this is kinda driving me crazy. > Any help/suggestion is more than welcome. The WebappClassLoader is just a ClassLoader that loads "down" instead of "up" like traditional ClassLoaders. It's not really webapp or context-specific in it's code... it's just that the servlet spec says that webapps need to load classes locally before looking up the ClassLoader tree, so this class was written to do just that. The WebappClassLoader isn't tied to the webapp/context other than it's the one that's been assigned to the context as it's ClassLoader. Instead of trying to reach-down from the ClassLoader to the StandardContext, why not do the reverse: register a ServletContextListener that configures the (already-created) ClassLoader. Something like this: public class CrazyClassLoaderConfigrationListener implements ServletContextListener { public void contextInitialized(ServletContextEvent e) { ClassLoader cl = this.getClass().getClassLoader(); if(!(cl instanceof CrazyClassLoader)) cl = Thread.currentThread().getContextClassLoader(); if(cl instanceof CrazyClassLoader) { ((CrazyClassLoader)cl) .configure(e.getServletContext() .getInitParameter("packages")); } else { e.getServletContext().log("Could not configure CrazyClassLoader"); } } } That's a little late to be setting the ClassLoader configuration, but it will happen before your servlets are loaded. Of course, you could also just use a .properties file to configure your ClassLoader. The real question is: what is it that you're really trying to do? - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx2fYgACgkQ9CaO5/Lv0PAs0ACgtV8J5d+y8n+CbxlNZpYJZndA qckAn2P0c45ioh8O7SyUsKfiYQfK3TPU =4TUr -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org