内嵌tomcat启动的代码

新建java工程,结构如下:

代码如下:  

public class App {

    static Tomcat tomcat8 = null;

    public static void main(String[] args) throws Exception { 
        tomcat8 = new Tomcat ();  
        tomcat8 .setBaseDir ("D:/myeclipse2014/tomcat-embed/res/temp/"); //不是必须的,但建议设置(参见DOC)
        tomcat8 .addWebapp ("/examples", "D:/myeclipse2014/tomcat-embed/res/webapps/examples/"); //webapp
        tomcat8 .addWebapp ("/manager", "D:/myeclipse2014/tomcat-embed/res/webapps/manager/"); //webapp
        tomcat8 .getConnector ().setURIEncoding ("UTF-8");
        tomcat8 .start ();
        tomcat8 .getServer().await(); 
    }

}

启动后, 访问:http://127.0.0.1:8080/examples/  ,截图如下: 

posted on 2016-11-15 13:13  小棍同行  阅读(267)  评论(0)    收藏  举报

导航