jetty,加载war包过程

来源:互联网 发布:南京旅游 知乎 编辑:程序博客网 时间:2024/06/16 18:50

1.下载jetty9.2

2.将全部的lib放入项目

3.主要加载项目代码如下:

public class JettyTest {
public static void main(String[] args) throws Exception {
String warPath = "D:\\projects\\workspace\\JettyTest\\src\\plc.war";  
   
Server server = new Server(8080);


        // Create a resource handler for static content.
        ResourceHandler staticResourceHandler = new ResourceHandler();
        staticResourceHandler.setResourceBase("./webapps/static/");
        staticResourceHandler.setDirectoriesListed(true);        
        //staticResourceHandler.setWelcomeFiles(new String[]{ "index.html",  });         
        //staticResourceHandler.setCacheControl("no-store,no-cache,must-revalidate");


        // Create context handler for static resource handler.
/*        ContextHandler staticContextHandler = new ContextHandler();
        staticContextHandler.setContextPath("/static");       
        staticContextHandler.setHandler(staticResourceHandler); */       


     // Create WebAppContext for JSP files.
        WebAppContext webAppContext = new WebAppContext();
        webAppContext.setContextPath("/");
        webAppContext.setWar(warPath);
     //   webAppContext.setResourceBase("./webapps/jsp/");
        // ??? THIS DOES NOT STOP DIR LISTING OF ./webapps/jsp/ ???
        webAppContext.setInitParameter("dirAllowed", "false");   


        // Create a handler list to store our static and servlet context handlers.
        HandlerList handlers = new HandlerList();
     //   handlers.setHandlers(new Handler[] { staticContextHandler, servletContextHandler });
        handlers.addHandler(webAppContext);
        // Add the handlers to the server and start jetty.
        server.setHandler(handlers);
        server.start();
        server.join();
}
}

中间出现的问题是,jsp无法解析org.apache.jasper.JasperException: java.err.nojdk,原因是因为当你的jdk版本高于6的时候,jsp解析包会默认用你jre的包,事实上jre里面也没有。   要使用jdk。->Preferences ->Java 中 Installed JREs 中的JRE home:换成JDK的安装路径  用整个jdk

0 0