Search in sources :

Example 1 with ParallelWebappClassLoader

use of org.apache.catalina.loader.ParallelWebappClassLoader in project spring-boot by spring-projects.

the class TomcatEmbeddedWebappClassLoaderTests method withWebappClassLoader.

private void withWebappClassLoader(File war, ClassLoaderConsumer consumer) throws Exception {
    URLClassLoader parent = new URLClassLoader(new URL[] { new URL(webInfClassesUrlString(war)) }, null);
    try (ParallelWebappClassLoader classLoader = new TomcatEmbeddedWebappClassLoader(parent)) {
        StandardContext context = new StandardContext();
        context.setName("test");
        StandardRoot resources = new StandardRoot();
        resources.setContext(context);
        resources.addJarResources(new WarResourceSet(resources, "/", war.getAbsolutePath()));
        resources.start();
        classLoader.setResources(resources);
        classLoader.start();
        try {
            consumer.accept(classLoader);
        } finally {
            classLoader.stop();
            classLoader.close();
            resources.stop();
        }
    }
    parent.close();
}
Also used : WarResourceSet(org.apache.catalina.webresources.WarResourceSet) URLClassLoader(java.net.URLClassLoader) StandardContext(org.apache.catalina.core.StandardContext) ParallelWebappClassLoader(org.apache.catalina.loader.ParallelWebappClassLoader) StandardRoot(org.apache.catalina.webresources.StandardRoot) URL(java.net.URL)

Aggregations

URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 StandardContext (org.apache.catalina.core.StandardContext)1 ParallelWebappClassLoader (org.apache.catalina.loader.ParallelWebappClassLoader)1 StandardRoot (org.apache.catalina.webresources.StandardRoot)1 WarResourceSet (org.apache.catalina.webresources.WarResourceSet)1