This code works with Tomcat 8.0:
File catalinaHome = new File("..."); // folder must exist Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); // HTTP port tomcat.setBaseDir(catalinaHome.getAbsolutePath()); tomcat.getServer().addLifecycleListener(new VersionLoggerListener()); // nice to have
You now have two options. Automatic deployment of any web application to catalinaHome/webapps :
// This magic line makes Tomcat look for WAR files in catalinaHome/webapps // and automatically deploy them tomcat.getHost().addLifecycleListener(new HostConfig());
Or you can manually add WAR archives. Note. They can be located anywhere on the hard drive.
source share