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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With