Search code examples
javatomcatclassloader

Override ParallelWebappClassLoader for one webapp


I need to set a custom wrapped classloader as ParallelWebappClassLoader for a one webapp only. Do I have a way to do that?

Also anyone have a idea how is the ParallelWebappClassLoader set as default class loader in a webapp in tomcat. When I add a debug point to loadClass(String) method it hits to loadClass method of ParallelWebappClassLoader. How can I change that to my custom class loader and the look in ParallelWebappClassLoader if I need?

Thanks

#tomcat #java #classloader #ParallelWebappClassLoader


Solution

  • You can specify a custom class loader via a Loader element nested in the Context element for your application.

    For example, add the following in the file META-INF/context.xml packaged in the WAR file:

    <Context>
      <Loader loaderClass="fully.quialified.package.name.of.your.ClassLoader" />
    </Context>