英文:
deploy war in jetty without web.xml
问题
我正在尝试将一个简单的Spring Boot应用程序部署为WAR文件到Jetty(9.4.30)。将test.war复制到*/webapps*目录中,应用程序会如预期启动。但是当我运行嵌入式Jetty时,浏览器中只会显示WAR文件的内容。
我应该如何在嵌入式Jetty中部署WAR文件?
public static void main(String[] args) {
try {
Server server = new Server(80);
HandlerCollection handlers = new HandlerCollection();
WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setWarResource(
Resource.newResource(new File("/test.war")));
handlers.addHandler(context);
server.setHandler(handlers);
server.start();
System.out.println("已启动!");
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
英文:
I'm trying to deploy a simple spring boot application as war into jetty (9.4.30).<br/>
Copying the test.war into the /webapps directory the application is started as expected. <br/>But when I run an embedded jetty I only get see the content of the war in the browser.<br/>
How should I deploy the war file in the embedded jetty?
public static void main(String[] args) {
try {
Server server = new Server(80);
HandlerCollection handlers = new HandlerCollection();
WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setWarResource(
Resource.newResource(new File("/test.war")));
handlers.addHandler(context);
server.setHandler(handlers);
server.start();
System.out.println("Started!");
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论