3

Is there a simple, programmatic way to quickly "deploy" and run a standard Java WAR file for local testing without having to install and configure external software packages like Tomcat or Jetty? Ideally something like Jetty's embeddable features but specifically for WAR files.

Java 6 provides the convenient Endpoint class which makes it easy to quickly deploy and test web services, is there something similar for WAR files? For example:

AppServer as = new javax.iwish.AppServer("localhost", 8080);
as.deploy("/", new File("path/to/my.war");
as.start();
maerics
  • 151,642
  • 46
  • 269
  • 291
  • What's wrong with embedded Jetty? There is no need to install and configure it, just drop some jars into classpath. – axtavt Sep 13 '11 at 18:14
  • I'd use Tomcat (Jetty should work the same). If you only need it for local testing, just download the ZIP and unpack... no need for any installation and/or configuration, simply start it. – home Sep 13 '11 at 18:16
  • possible duplicate of [Light Java servlet container for development](http://stackoverflow.com/questions/5186521/light-java-servlet-container-for-development) –  Sep 13 '11 at 18:20
  • Perhaps using ANT to deploy in Tomcat and using HttpUnit to verify if it is working as expected? – Usman Saleem Sep 13 '11 at 18:33

1 Answers1

8

I asked too soon, it looks like Jetty does exactly what I need:

Server server = new Server(8080);
server.setHandler(new WebAppContext("foo.war", "/"));
server.start();

Remarkably close to my dreamed up API =D

tobias_
  • 468
  • 5
  • 21
maerics
  • 151,642
  • 46
  • 269
  • 291
  • 2
    using the [maven-jetty-plugin](http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin#) is much easier and faster, you don't even need to start and stop the server in most cases. –  Sep 13 '11 at 19:01
  • 1
    @Jarrod Roberson: right but then you have to use maven, right? I'm trying to reduce the number of dependencies in this project... – maerics Sep 13 '11 at 19:08