版权声明:原创文章转载请声明出处https://blog.csdn.net/qq_40374604 https://blog.csdn.net/qq_40374604/article/details/84326016
来源转载
另一篇参考博客: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();