package fu.kung;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Embedded;
public class Tomcat {
private static final String CATALINA_HOME = "F:/downloads/apache-tomcat-5.5.25-embed";
private static final String APP_BASE = "E:/project files";
private static final String DOC_BASE = "E:/project files/veges/src/main/webapp";
private static final String PATH = "/veges";
private static final String HOST = "localhost";
private static Embedded tomcat = null;
public static void main(String[] args) {
initEmbedded();
initShutdownHook();
startTomcat();
}
private static void startTomcat() {
try {
tomcat.start();
} catch (LifecycleException e) {
e.printStackTrace();
}
}
private static void initShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
tomcat.stop();
} catch (LifecycleException e) {
e.printStackTrace();
}
}
});
}
private static void initEmbedded() {
tomcat = new Embedded();
tomcat.setCatalinaHome(CATALINA_HOME);
Engine engine = tomcat.createEngine();
Host host = tomcat.createHost(HOST, APP_BASE);
Context myContext = tomcat.createContext(PATH, DOC_BASE);
host.addChild(myContext);
engine.addChild(host);
engine.setDefaultHost(HOST);
tomcat.addEngine(engine);
Connector connector = tomcat.createConnector(HOST, 8080, false);
tomcat.addConnector(connector);
}
}
[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7845854/viewspace-1034565/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7845854/viewspace-1034565/