How can I deploy a WAR in an embedded Jetty 8?

2019-03-20 04:43发布

With the following code, how can I deploy a WAR application located on the classpath ?

private Server s; 

@BeforeClass
public static void setUp() throws Exception {
    // Start http server
    Random r = new Random();
    int port = 1024 + r.nextInt(8976);
    s = new Server(new InetSocketAddress("127.0.0.1", port));

    // Add my WAR for deployment here ...

    s.start();
}

Jetty 8.0.1
JDK 6

标签: java Jetty war
1条回答
等我变得足够好
2楼-- · 2019-03-20 05:15

Something like

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar(warURL);
    server.setHandler(webapp);

The war does not have to be on the class path.

查看更多
登录 后发表回答