Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

war

jetty

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

like image 279
Stephan Avatar asked Mar 21 '12 15:03

Stephan


People also ask

How do you deploy war on Jetty?

Deploying by Copying WAR The easiest way to deploy a web application to Jetty server is probably by copying the WAR file into the $JETTY_HOME/webapps directory. Jetty will scan its $JETTY_HOME/webapps directory at startup for web applications to deploy. Our new app will be deployed at /jetty-app context.

Is Jetty better than Tomcat?

On whole, the key difference between Tomcat and Jetty is the fact that Apache Tomcat places great stress on being up to date with the latest specification, while Eclipse Jetty prioritizes the needs of their user community which tends to result on an emphasis on performance.

How do I create a WAR file for web application?

To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file. Go inside the project directory of your project (outside the WEB-INF), then write the following command: jar -cvf projectname.


1 Answers

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.

like image 68
Bruno Grieder Avatar answered Sep 21 '22 17:09

Bruno Grieder