Jump to: navigation, search


< Jetty‎ | Feature
Revision as of 15:44, 18 August 2010 by Boulay.intalio.com (Talk | contribs)


Jetty is just a Java program that can be run like any other Java program once you set up a classpath. For example, the SimplestServer from the Embedding Jetty Tutorial can be run as follows:

java -cp $JETTY_CLASSPATH org.eclipse.jetty.embedded.SimplestServer

Similarly, if you configure your server with jetty.xml rather than a Java main, the server can be run with:

java -cp $JETTY_CLASSPATH org.eclipse.jetty.xml.XmlConfiguration etc/jetty.xml

The difficult part of both these examples is knowing what must be on the JETTY_CLASSPATH. The jetty server comes in over 46 jars, so working out exactly which are needed can be difficult. If you develop with Maven, these jar dependencies can be managed for you, but you still need to setup a classpath when running from the command line.

The start.jar mechanism is an executable jar file that builds a class path and then executes your main program. It is a generic mechanism that you can use with any Java program. Its behaviour is controlled by a start.config file. The standard start.jar comes with a start.config file for Jetty, so that you can start Jetty with:

java -jar start.jar

You can see the effective command line generated by start.jar by providing the --dry-run parameter:

java -jar start.jar --dry-run

which for the default case generates:

/usr/lib/jvm/java-1.5.0-sun- \
-Djetty.home=/home/gregw/src/jetty-7.0.0/jetty-distribution/target/distribution \
-cp /home/gregw/src/jetty-7.0.0/jetty-distribution/target/distribution/resources:\
/home/gregw/src/jetty-7.0.0/jetty-distribution/target/distribution/lib/jetty-io-7.0.0.RC6-SNAPSHOT.jar \
org.eclipse.jetty.xml.XmlConfiguration \


Building the Environment

The start.jar builds an environment of Java system properties and start properties that parameterize the start mechanism and the execution of the program. In a start.config, the string ${name} is expanded to a start property and $(name) is expanded to either a start property or a system property.

The main property set by the default start.config is jetty.home, which is assumed to be the directory in which start.jar is deployed. If the jetty.home is not set with a -Djetty.home then ".", ".." and some well known directories are searched for start.jar.

The $(version) property is also determined by examining the manifest of the start.jar.

Building the Classpath

The default start.config assumes that all the jetty jars will be in a directory tree under ${jetty.home}/lib The following jars are put on all classpaths built by the default start.config:


If you don't specify any OPTIONS, then the following entries are also added by default:


This is sufficient to run most standard web applications.

If the system property ${path} is defined, then it is treated as a classpath string and prepended to the generated classpath. If the system property ${lib} is defined, then it is treated as a directory of jars and all jars discovered are prepended to the generated classpath.


You can specify options to the start.jar to change the default jars added to the classpath:

java -jar start.jar OPTIONS=Server,jmx,ajp,setuid

The available options can be listed with

java -jar start.jar --help

If an option is specified, then the default jars listed above are not added to the classpath. There are three types of options available:

  • Convenience Options–By convention, options starting with a capital letter are convenience options that include many other options. For example the "Server" option includes all the options commonly needed to run a server: xml,server,security,servlet,webapp,deploy and servlets options; while the option "server" contains just the jars for the core HTTP server. "All" is the other convenience option.
  • Known module options–The main known jetty modules each have an option predefined to select their required jars. Known options include xml,server, security, servlet, webapp, deploy, serlvets, rewrite, jmx, ajp, jndi, annotations, setuid, policy and client.
  • Discovered options–Directories within ${jetty.home}/lib can be discovered as options. The "lib/ext", "lib/jsp" and "lib/jta" are directories that can be discovered as an options

Building the Arguments

The jetty start.config file lists has etc/jetty.xml as the default command line argument, which in the default case is the name of the configuration file passed to the XmlConfiguration main. If additional configuration files are needed, then all the configuration files must be listed on the command line along with the OPTIONs required for the classpath. For example, the following runs Jetty with JMX and AJP connector:

java -jar start.jar OPTIONS=Server,jmx,ajp etc/jetty-jmx.xml etc/jetty.xml etc/jetty-ajp.xml

Use the --help parameter to list the available XML configuration files.

Running the Main

The jetty start.config has org.eclipse.jetty.xml.XmlConfiguration as the main class to run. You can replace it with another class by setting the start.class system property.

Setting Defaults: start.ini

If the file "start.ini" exists in the same directory as start.jar, then it is read and every non comment line is treated as a command line argument. The following start.ini sets the options and default configuration files for using the server with JMX and SSL:

# Jetty start.jar arguments

As well as normal start.jar arguments, it is possible to put JVM arguments in a start.ini. However, because these cannot affect the JVM that is running start.jar, the --exec option should be provided so that a new JVM is spawned with the arguments. The following start.ini example sets the JVM heap memory and enables remote JMX management:

# Jetty start.jar arguments