Embedding Tomcat 7
Tomcat 6public static void main(String[] args) throws Exception {
String weppAppHome = args;
Integer port = Integer.valueOf(args);
Server server = new Server(port);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/myapp");
webapp.setCompactPath(true);
webapp.setDescriptor(weppAppHome + "/WEB-INF/web.xml");
webapp.setResourceBase(weppAppHome);
webapp.setParentLoaderPriority(true);
server.setHandler(webapp);
server.start();
server.join();
}
Tomcat 7
public static void main(String[] args) throws Exception {
String appBase = args;
Integer port = Integer.valueOf(args);
Tomcat tomcat = new Tomcat();
tomcat.setPort(port);
tomcat.setBaseDir(".");
tomcat.getHost().setAppBase(appBase);
String contextPath = "/myapp";
// Add AprLifecycleListener
StandardServer server = (StandardServer)tomcat.getServer();
AprLifecycleListener listener = new AprLifecycleListener();
server.addLifecycleListener(listener);
tomcat.addWebapp(contextPath, appBase);
tomcat.start();
tomcat.getServer().await();
}
页:
[1]