// embeddeding implementation of sthg (JPA, JSF) can lead to classloading issues if we don't // enrich the webapp // with our integration jars // typically the class will try to be loaded by the common classloader // but the interface implemented or the parent class // will be in the webapp @Override public void start() throws LifecycleException { super.start(); // do it first otherwise we can't use this as classloader // mainly for tomee-maven-plugin initAdditionalRepos(); if (additionalRepos != null && !additionalRepos.isEmpty()) { for (final File f : additionalRepos) { final DirResourceSet webResourceSet = new PremptiveDirResourceSet(resources, "/", f.getAbsolutePath(), "/"); resources.addPreResources(webResourceSet); } resources.setCachingAllowed(false); } // add configurer enrichments if (configurer != null) { // add now we removed all we wanted final URL[] enrichment = configurer.additionalURLs(); for (final URL url : enrichment) { super.addURL(url); } } // add internal enrichments for (final URL url : SystemInstance.get().getComponent(WebAppEnricher.class).enrichment(this)) { super.addURL(url); } // WEB-INF/jars.xml final File war = Contexts.warPath(CONTEXT.get()); final File jarsXml = new File(war, "WEB-INF/" + QuickJarsTxtParser.FILE_NAME); final ClassLoaderConfigurer configurerTxt = QuickJarsTxtParser.parse(jarsXml); if (configurerTxt != null) { configurer = new CompositeClassLoaderConfigurer(configurer, configurerTxt); } stopped = false; }
@Override public TomEEWebappClassLoader copyWithoutTransformers() { final TomEEWebappClassLoader result = new TomEEWebappClassLoader(getParent()); result.additionalRepos = additionalRepos; result.configurer = configurer; super.copyStateWithoutTransformers(result); try { result.start(); } catch (LifecycleException e) { throw new IllegalStateException(e); } return result; }
public void internalDestroy() { try { if (!stopped) { try { internalStop(); } catch (final LifecycleException e) { // no-op } } super.destroy(); } finally { cleanUpClassLoader(); } }
public void internalStop() throws LifecycleException { if (stopped) { return; } // reset classloader because of tomcat classloaderlogmanager // to be sure we reset the right loggers final Thread thread = Thread.currentThread(); final ClassLoader loader = thread.getContextClassLoader(); thread.setContextClassLoader(this); try { super.stop(); // super.destroy(); if (webResourceRoot != null) { webResourceRoot.internalStop(); webResourceRoot = null; } stopped = true; } finally { thread.setContextClassLoader(loader); if (!forceStopPhase) { cleanUpClassLoader(); } } }
public void addURL(final URL url) { if (configurer == null || configurer.accept(url)) { super.addURL(url); } }