Tomcat7内嵌服务器

import java.io.File;

import org.apache.catalina.startup.Tomcat;

public class DevelopServer {
	private static String PROJECT_HOME = System.getProperty("user.dir");
	private static String BASEDIR = PROJECT_HOME + File.separator + "/Tomcat";
	private static String WEBAPPDIR = PROJECT_HOME + File.separator + "WebContent";
	
	private static Tomcat tomcat = null;  
	public static void main(String[] args){
		try {  
            long startTime = System.currentTimeMillis();  
              
            tomcat = new Tomcat();  
            // 设置Tomcat的工作目录:工程根目录/Embedded/Tomcat  
            tomcat.setBaseDir(BASEDIR);  
            tomcat.setPort(8080);  
            tomcat.addWebapp("", WEBAPPDIR);  //第一个参数是发布目录
            tomcat.enableNaming();//执行这句才能支持JDNI查找  
            tomcat.getConnector().setURIEncoding("UTF-8");  
            tomcat.start();  
            System.err.println("Tomcat started in " + (System.currentTimeMillis() - startTime) + " ms.");  
            tomcat.getServer().await();//让服务器一直跑  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
	}
}

你可能感兴趣的:(tomcat7)