On 13/01/2017 11:14, Tom Eugelink wrote: > I'm trying to migrate a very old ANT based project into the future, the > ANT scripts I inherited are (of course) very complex, so I need to make > babysteps. The first thing I did was compile the Java code with Maven and > thus replaced a lot of copy statements and checked in lib directories with > dependencies. This is working fine, but it also means that there is no > single directory anymore where all the classfiles, jars, configuration > files, etc are copied to. So now I need a way to start Tomcat for > developers using (still) separated directories. > > The best approach seemed like to start Tomcat embedded, this also allows > me to use it for running cucumber and integration tests against. The thing > is I cannot get it to work, even after searching google, stackoverflow and > reading the Tomcat (8.0.39) configuration guides for 2 days. It should, I > would not mind if it did, but it does not. > > To begin I have a maven project with: > - classes in target/classes > - web files in webapps > - configuration files in /somewhere/outside/the/project/cfg > > This what I have so far: > StandardContext standardContext = > (StandardContext)tomcat.addWebapp("/myapp, > "/path/to/maven/project/webapps); > standardContext.setCrossContext(true); > standardContext.addParameter("SomeOwnFramework.Home", > "/somewhere/outside/the/project"); > standardContext.addParameter("SomeOwnFramework.ContainerName", > "MijnCaress Backend Container"); > > standardContext.addParameter("SomeOwnFramework.XmlConfigurationFile", > "/somewhere/outside/the/project/cfg/Framework-backend.xml"); > > standardContext.getNamingResources().addResource(createJdbcResource()); > // returns a > org.apache.tomcat.util.descriptor.web.ContextResource > > org.apache.catalina.webresources.StandardRoot standardRoot = new > org.apache.catalina.webresources.StandardRoot(standardContext); > standardRoot.setCachingAllowed(true); > standardRoot.setCacheMaxSize(100000); > // add classes > standardRoot.addPreResources(new > org.apache.catalina.webresources.DirResourceSet(standardRoot, > "/WEB-INF/classes", new File("target/classes").getAbsolutePath(), > "/")); > // add configuration files > standardRoot.addPostResources(new > org.apache.catalina.webresources.DirResourceSet(standardRoot, > "/WEB-INF/classes", new > File("/somewhere/outside/the/project/cfg").getAbsolutePath(), > "/")); > standardContext.setResources(standardRoot); > > This ends with a ClassNotFoundException on a class that is in > target/classes, also if I remove the configuration files resource. > The target/classes absolute path is correct, exists and contains the class. > > It would be great to get some pointers on why this is not working.
Class loader resources have special handling. I think you'll be able to get this to work with: standardRoot.createWebResourceSet(CLASSES_JAR, "/WEB-INF/classes", new File("target/classes").getAbsolutePath(), null, "/"); If that doesn't work, I'd recommend using a debugger to figure out what is going on. It wouldn't surprise me to find we need to extend the API as more use cases emerge. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org