jetty,加载war包过程

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值