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/
 
 


16 Comments

DJ · 02/05/2008 at 09:22

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.

 

 

Stephan Schmidt · 03/05/2008 at 07:10

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

pmorelli · 15/05/2008 at 05:27

dist link goes 404

Anonymous · 15/05/2008 at 13:32

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!

Jan Bartel · 15/05/2008 at 16:36

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

Jan Bartel · 15/05/2008 at 16:47

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

Clay · 14/07/2008 at 14:01

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

Jan Bartel · 25/07/2008 at 00:26

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

Alex Russell · 09/11/2008 at 21:55

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

Jan Bartel · 09/11/2008 at 22:56

Hi Alex,

In fact, the jetty-runner jar is pre-built and can be downloaded from the main maven repo at:

http://repo2.maven.org/maven2/org/mortbay/jetty/jetty-runner/

I updated the blog post a little with this info.

cheers

Jan

Alex Russell · 09/11/2008 at 23:23

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

Adrian · 05/03/2009 at 04:27

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.

Jan Bartel · 19/04/2009 at 05:37

Adrian,
I think its just cntrl-c, at least for now. However, if you want programmatic control, perhaps you’d be better off embedding a jetty server? Check out the jetty wiki pages on embedding if you haven’t already: http://docs.codehaus.org/display/JETTY/Embedding+Jetty.

Bruce Edge · 07/05/2009 at 06:08

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.

wonderer · 20/08/2009 at 20:48

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

sameer · 04/01/2013 at 03:32

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.