Tushar Madhukar wrote:
I have some utility classes in $tomcat/shared/lib directory, which are used
by several webapps. These need to be initialized before any of my webapps
are called by the client. One of these shared classes gets a reference to
its class loader, by calling Thread.currentThread().getContextClassLoader().
I understand that in Tomcat, there are separate class loaders for
shared/libclasses and webapp
classes (and they have a parent-child relation). Now, if this shared class
is initialized from any of my webapps (say, using contextInitialized()), the
Thread.getContextClassLoader() method returns the webapp class loader,
instead of the shared/lib class loader. How do I get the correct class
loader?
You might try accessing the parent classloader from the webapp classloader,
but it isn't anywhere near a clean approach, as you would then mix code
extremely dependent on Tomcat internals with code of your applications.
As far as I understand, one way to achieve this would be if Tomcat provides
a hook that can be invoked while it starts up (something similar to
Runtime.addShutdownHook()). Basically, I am looking for a way to force the
shared/lib class loader to load the classes before any of the my webapps are
initialized.
Various Tomcat components do provide Lifecycle Listeners. You might be able
to do what you're looking for by placing such a listener on each Tomcat Context
you're running. I've been looking for a way to "inject" a listener automatically
to each context, by first placing a listener on the Host to listen for Contexts
to be attached, but it's nowhere near straightforward -- and if I recall
correctly, one problem with this approach was that the webapp was more or less
fully started and initialized before it was added to the Host. Or then I just
couldn't find the proper event to listen for.
For details, please see the documentation for the Tomcat version you're using.
--
..Juha
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]