Wednesday Apr 30, 2008
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.warVoila! 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 my2Or, 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.xmlYou 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.warYou 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 \The syntax of the --jdbc argument is:
--lib ~/src/tools/derby/ --lib ~/src/tools/atomikos \
--jdbc org.apache.derby.jdbc.EmbeddedXADataSource "databaseName=testdb;createDatabase=create" "jdbc/mydatasource" \
my.war
--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>And as if all that wasn't enough, you can get full configuration control using a jetty.xml configuration file:
--classes <dir>
java -jar jetty-runner.jar --config my/jetty.xml my.warYou 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:
- 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 - mvn clean install
- the jar file to use will be in target/jetty-runner-<tag>.jar
Posted at 03:00PM Apr 30, 2008 by janb in General | Comments[15]
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.
Posted by DJ on May 03, 2008 at 12:22 AM EST #
Thanks
-stephan
Posted by Stephan Schmidt on May 03, 2008 at 10:10 PM EST #
Posted by pmorelli on May 15, 2008 at 08:27 PM EST #
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!
Posted by Anonymous on May 16, 2008 at 04:32 AM EST #
Thanks for pointing that out.
cheers
Jan
Posted by Jan Bartel on May 16, 2008 at 07:36 AM EST #
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
Posted by Jan Bartel on May 16, 2008 at 07:47 AM EST #
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
Posted by Clay on July 15, 2008 at 05:01 AM EST #
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
Posted by Jan Bartel on July 25, 2008 at 03:26 PM EST #
Posted by Alex Russell on November 10, 2008 at 02:55 PM EST #
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. cheersJan
Posted by Jan Bartel on November 10, 2008 at 03:56 PM EST #
Posted by Alex Russell on November 10, 2008 at 04:23 PM EST #
Posted by Adrian on March 05, 2009 at 09:27 PM EST #
Posted by Jan Bartel on April 19, 2009 at 08:37 PM EST #
Posted by Bruce Edge on May 07, 2009 at 09:08 PM EST #
Posted by wonderer on August 21, 2009 at 11:48 AM EST #