jetty7內嵌程式碼配置
阿新 • • 發佈:2018-11-22
來源轉載
另一篇參考部落格:https://blog.csdn.net/robinpipi/article/details/7557035?utm_source=blogxgwz9
以war包形式啟動:
String warPath = "../project/target/project.war"; Server server = new Server(8080); WebAppContext context = new WebAppContext(); context.setWar(warPath); context.setContextPath("/"); context.setClassLoader( Thread.currentThread().getContextClassLoader()); server.setHandler(context); server.start(); server.join();
直接在專案中啟動:
String webapp = "../project/src/main/webapp"; Server server = new Server(8080); WebAppContext context = new WebAppContext(); context.setDescriptor(webapp + "/WEB-INF/web.xml"); context.setResourceBase(webapp); context.setContextPath("/"); context.setClassLoader( Thread.currentThread().getContextClassLoader()); server.setHandler(context); server.start(); server.join();