use of org.apache.catalina.webresources.DirResourceSet in project kontraktor by RuedigerMoeller.
the class TomcatEmbeddedMain method main.
public static void main(String[] args) throws Exception {
String webappDirLocation = "src/main/webapp/";
Tomcat tomcat = new Tomcat();
if (!new File(webappDirLocation + "client/index.html").exists()) {
System.out.println("Please run with working dir: '[..]examples/servlet");
System.exit(-1);
}
// The port that we should run on can be set into an environment variable
// Look for that variable and default to 8080 if it isn't there.
String webPort = System.getenv("PORT");
if (webPort == null || webPort.isEmpty()) {
webPort = "8080";
}
tomcat.setPort(Integer.valueOf(webPort));
StandardContext ctx = (StandardContext) tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
// Declare an alternative location for your "WEB-INF/classes" dir
// Servlet 3.0 annotation will work
File additionWebInfClasses = new File("target/classes");
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
ctx.setResources(resources);
tomcat.start();
tomcat.getServer().await();
}
use of org.apache.catalina.webresources.DirResourceSet in project tomee by apache.
the class TomEEWebappClassLoader method start.
// 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 {
// do it first otherwise we can't use this as classloader
super.start();
// 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;
}
use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.
the class JsfTomcatApplicationListenerIT method embeddedJarWithoutAppResources.
@Test
public void embeddedJarWithoutAppResources() throws LifecycleException {
ContextMock contextMock = new ContextMock();
File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar");
JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
jarWarResourceSet.init();
DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
contextMock.init(jarWarResourceSet, dirResourceSet);
callApplicationEvent(contextMock);
assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(2);
}
use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.
the class JsfTomcatApplicationListenerIT method embeddedJarWithoutAppResources2.
@Test
public void embeddedJarWithoutAppResources2() throws LifecycleException {
ContextMock contextMock = new ContextMock();
File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar");
JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
jarWarResourceSet.init();
DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
contextMock.init(dirResourceSet, jarWarResourceSet);
callApplicationEvent(contextMock);
assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(2);
}
use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.
the class JsfTomcatApplicationListenerIT method embeddedWarWithoutAppResources.
@Test
public void embeddedWarWithoutAppResources() throws LifecycleException {
ContextMock contextMock = new ContextMock();
File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.war");
JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
jarWarResourceSet.init();
DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
contextMock.init(jarWarResourceSet, dirResourceSet);
callApplicationEvent(contextMock);
assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(0);
}
Aggregations