在Jetty中部署WAR文件而无需web.xml。

huangapple 未分类评论43阅读模式
英文:

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?

在Jetty中部署WAR文件而无需web.xml。

public static void main(String[] args) {
	try {
		Server server = new Server(80);

		HandlerCollection handlers = new HandlerCollection();

		WebAppContext context = new WebAppContext();
		context.setContextPath(&quot;/test&quot;);
		context.setWarResource(
				Resource.newResource(new File(&quot;/test.war&quot;)));
		handlers.addHandler(context);
		server.setHandler(handlers);

		server.start();
		System.out.println(&quot;Started!&quot;);
		server.join();
	} catch (Exception e) {
		e.printStackTrace();
	}
}

huangapple
  • 本文由 发表于 2020年7月23日 14:08:52
  • 转载请务必保留本文链接:https://java.coder-hub.com/63047916.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定