If you’re looking for a fast and easy way to run your webapp, without needing to install and administer a Jetty distro, then look no further, the Jetty Runner is here! The idea of the Jetty Runner is extremely simple – run a webapp from the command line using a single jar and as much default configuration as possible:

  java -jar jetty-runner.jar my.war

Voila! Jetty will start on port 8080 and deploy the my.war webapp. Couldn’t get much simpler, could it?

You can also deploy multiple webapps – either packed or unpacked wars – from the command line. In this example, my.war will be available at http://host:8080/one and the my2 webapp will be available at http://host:8080/two:

  java -jar jetty-runner.jar --path /one my1.war --path /two my2

Or, for those webapps that need a little more configuration, you can run them via jetty context config files:

  java -jar jetty-runner.jar contexts/my.xml

You can configure the most common things from the command line, like the port to start on, and whether to generate a request log or not:

 java --jar jetty-runner.jar --port 9090 --log my/request/log/goes/here my.war

You can even configure a JDBC JNDI Resource entry right on the command line. Here’s an example to define a Postgres DB available in JNDI at java:comp/env/jdbc/mydatasource:

 java -jar jetty-runner.jar    --lib ~/src/tools/derby/ --lib ~/src/tools/atomikos     --jdbc org.apache.derby.jdbc.EmbeddedXADataSource "databaseName=testdb;createDatabase=create" "jdbc/mydatasource"    my.war

The syntax of the –jdbc argument is:

 --jdbc <classname of Driver or XADataSource> <db properties> <jndiname>

You’ll also have to tell jetty where to find your database driver and Atomikos, which we use to provide a transaction manager and wrap XA and non-XA Resources into a DataSource you can access from your webapp.

You’ll notice the –lib argument, which is one way to tell jetty about extra jars you want to put onto the container’s classpath. We also give you:

 --jar <filename> --classes <dir>

And as if all that wasn’t enough, you can get full configuration control using a jetty.xml configuration file:

 java -jar jetty-runner.jar --config my/jetty.xml my.war

You can see all your options with:

 java -jar jetty-runner.jar --help

How to get the jetty-runner.jar

The jetty runner is in the jetty-contrib svn repository and as such is no longer distributed as part of the standard jetty release.
At present, there is no distribution of the modules in the jetty-contrib repo (coming soon), however they are tagged
with the same release tags as the main jetty release.

So to obtain the jetty runner:

  1. do an svn checkout from https://svn.codehaus.org/jetty-contrib/tags/jetty-contrib-<tag>, where tag is 7.0.0pre1 or higher release number, eg:

    https://svn.codehaus.org/jetty-contrib/tags/jetty-contrib-7.0.0pre1

  2. mvn clean install
  3. the jar file to use will be in target/jetty-runner-<tag>.jar

UPDATE 10 November 2008

 

The jetty-runner jar can be downloaded form the main maven repo at: http://repo2.maven.org/maven2/org/mortbay/jetty/jetty-runner/

 

 

Jetty Runner

16 thoughts on “Jetty Runner

  • May 2, 2008 at 9:22 am
    Permalink

    Recently I started using Jetty as a Maven Plugin.  Now I feel like this is one of finest software in Java I have ever seen.

     

     

  • May 3, 2008 at 7:10 am
    Permalink

    Excellent, some years ago we had to write a lot of code ourselves to use Jetty as a runner for SnipSnap, great to see this out of the box.

    Thanks
    -stephan

  • May 15, 2008 at 5:27 am
    Permalink

    dist link goes 404

  • May 15, 2008 at 1:32 pm
    Permalink

    I downloaded the jetty pre1 distro and runner is not included. I then I downloaded jetty-runner-7.0.0pre1.jar from the maven site above and the manifest doesnt hava main class entry.

    As such it complains:  Failed to load Main-Class manifest attribute from jetty-runner-7.0.0pre1.jar

    Good idea – and would like to be able to use it!

  • May 15, 2008 at 4:36 pm
    Permalink

    Ooops, the distro directory got changed after I published the blog entry. Just go to http://dist.codehaus.org/jetty and click down to the jetty 7 prereleases directory. I’ll fix up the link the blog.

    Thanks for pointing that out.

    cheers
    Jan

  • May 15, 2008 at 4:47 pm
    Permalink

    Oooops again!

    We’re doing a bunch of changes to the way Jetty builds in the 7.x series. I didn’t realize we were no longer going to be distributing the sources in the distro downloads.

    So, in order to use the Jetty Runner jar, you need to check out the jetty-contrib svn repo, and build it. The svn repo is at:

     https://svn.codehaus.org/jetty-contrib/trunk/jetty-runner

     or for the 7.0.0pre1 release:

      https://svn.codehaus.org/jetty-contrib/tags/jetty-contrib-7.0.0pre1/

    Build it and you’ll find in your target directory a "jetty-runner.jar". NOTE that the artifact called jetty-runner-7.0.0pre1.jar in the target directory is NOT the final artifact. The target/jetty-runner.jar is the assembled jar that contains all the necessary dependency classes.

    Sorry for the confusion, will update the blog entry to reflect reality.

    cheers
    Jan

  • July 14, 2008 at 2:01 pm
    Permalink

    Hi,

    I’ve been using jetty-runner over the last few days and I really like it.  I’m a newbie to Jetty, so pardon me for asking what is likely obvious.  I’d like to use a HTAccessHandler with the war I’m running for added security.  Where would I configure that?  In a context xml?  I tried that approach with a WebAppContext and adding a handler with the HTAccessHandler to no avail.

    If there’s a more appropriate forum for this, please let me know.

    Thanks,
    Clay

  • July 25, 2008 at 12:26 am
    Permalink

    Hi Clay,

    For the future,  better place for questions and to get help is the jetty mailing list:
    user@jetty.codehaus.org

    How did you try adding the HTAccessHandler? You should have been able to use a context xml file and call setSecurityHandler, passing in an instance of the HTAccessHandler.

    If you want to reply, it would be good if you did it on the list, so others can see and benefit 🙂

    cheers
    Jan

  • November 9, 2008 at 9:55 pm
    Permalink

    brilliant! This is SUPER handy…wish there were pre-rolled jars, though.

  • November 9, 2008 at 11:23 pm
    Permalink

    Ahhh…thanks for pointing me in the right direction. Building from source wasn’t much of a pain, but it’s great to be able to point scripts at the maven repo.
    Again, nice work on this…it’s the easiest way I’ve ever seen to portably turn a directory of junk into a runnable web project.
    Regards

  • March 5, 2009 at 4:27 am
    Permalink

    Hi,
    this feature is really great. However is there any way to stop the process (other than the Ctrl^C method)? I need to be able to manage this process programmatically.
    The stop port feature in standard jetty doesn’t seem to work here.
    thanks.

  • May 7, 2009 at 6:08 am
    Permalink

    Any way to get this to run headless?
    I tried -Djava.awt.headless=true
    I can’t get it running unless there’s a logged in X session.

  • August 20, 2009 at 8:48 pm
    Permalink

    Any chance of getting the last stable version (6.1.19) in maven?

  • January 4, 2013 at 3:32 am
    Permalink

    I want to execute war file using command prompt with the help of Jetty Runner excecute war file .i have jetty runner.jar file , how i can set as directory ? when i have manually test in command prompt like java -jar jetty-runner-7.0.0v20091005 unable to access jarfile jetty-runner -7.0.0.v20091005. can any one please let steps .advance thanks.

Comments are closed.