BACK | INDEX | EXIT | NEXT

# Getting Started

Introduction
So you want to skip all the preliminary reading and just get Jetty up and going? No problem, but we do recommend that once you've satisfied the urge to play around with it in your environment that you go back and visit the tutorial, particularly if you're so enthused that you want to contribute to Jetty!
Firstly, if you haven't already done it, you need to download Jetty using one of the methods provided on the download page. Once successfully downloaded, follow the links for running the demonstrations provided with Jetty.
Running the Jetty demonstrations
The installation includes the ability to serve the Jetty web site pages locally as a demonstration of Jetty's capabilities. The demonstrations include various servlets, JSP integration, SSL integration and a web application.
There are 4 ways to run it:

- using start.jar
- using the Ant build environment
- using prepared scripts
- manually

Of the above options, the easiest is to use the start.jar method.Alternatively, if you have Ant installed, you can use it to run the demonstration content. The scripts handle all the housekeeping tasks associated with getting a server started, and are provided as Unix shell scripts and as (unmaintained) Window bat files (you should treat them as examples, and feel free to brew your own). Finally, you can manually configure your environment and run the server by hand.
Quick start with start.jar
Starting Jetty

The start.jar file in the Jetty distribution may be run with

      java -jar start.jar <configfile> ...

For example

      java -jar start.jar etc/admin.xml etc/demo.xml

On some systems with graphical file browsers, it may be possible to start jetty by double clicking on this jar file. For more details see

      $JETTY_HOME/src/org/mortbay/start/README.txt
    or
      http://jetty.mortbay.org/javadoc/org/mortbay/start/Main.html

If jetty is not being started from the current directory, then the jetty.home property should be set:

      java -Djetty.home=C:\jetty -jar start.jar <configfile> ...

If JSPs do not work with this start method, you may want to clearly specify the location of the JDK so the compiler can be accessed:

      java -Djava.home=C:\j2sdk1.4.1 -jar start.jar <configfile> ...

If an extra classpaths are needed, they can be added with the jetty.class.path property:

      java -Djetty.class.path=/usr/share/java -jar start.jar <configfile> ...

If no configuration file is provided, start.jar will use etc/admin.xml and etc/jetty.xml

Stopping Jetty

Programs started with the start.jar mechanism may be stopped with the stop.jar:

       java -jar stop.jar

This connects via a local port to stop the server. The default port can be set wi th the STOP.PORT system property (a port of < 0 disables the stop mechanism). If the STOP.KEY system property is set, then a random key is generated and written to stdout. This key must be passed to the stop.jar. eg

      [540] java -DSTOP.PORT=9999 -DSTOP.KEY -jar start.jar
      1rukbu7owi3uo
      17:39:49.082 EVENT  Starting Jetty/4.2.10pre0
      ...

      [526] java -DSTOP.PORT=9999 -DSTOP.KEY=1rukbu7owi3uo -jar stop.jar

Unix shell script
You must already have a Java environment installed and configured (ie you must have the $JAVA_HOME environment variable set).
Then, set up the fundamental Jetty evironment variable $JETTY_HOME. This must point to the directory into which you installed Jetty:

> export JETTY_HOME=<jetty install directory>

Running a simple server
To verify Jetty on your system, type the following command to start a very simple one-page server:

> $JETTY_HOME/bin/jetty.sh run

Use your browser to go to the following location to see the sample page:

> http://localhost:8080

If the script doesn't work for you, either try the Ant version, or follow the manual instructions .
Running the Jetty demonstrations
To run the more sophisticated demonstrations, execute the following command (if you are still running the previous example, don't forget to kill it first):

> $JETTY_HOME/bin/jetty.sh demo

Use your browser to go to the following location:

> http://localhost:8080

Select the Demonstrations link to explore the servlets provided. Here is page you should see.
Windows .bat file
NOTE: Due to problems with the servlet security model, it is vital that Windows users use the exact case for drive letters, URLs and filenames.
To run the demonstrations under Windows, ensure that your Java environment is set up, then set the fundamental Jetty evironment variable %JETTY_HOME%. This must point to the directory into which you installed Jetty:

> set JETTY_HOME=<jetty install directory>

Running a simple server
To verify Jetty on your system, type the following command to start a very simple one-page server:

> %JETTY_HOME%\bin\jetty.bat

Use your browser to go to the following location:

> http://localhost:8080

If you have problems:

- try installing Jetty in a path with no spaces in the directory name.
- check that the case of JETTY_HOME is exactly the same as reported by your system

If you still cannot get the bat file to work, then try the Ant option, or set it up manually.
Running the Jetty demonstrations
To run the more sophisticated servlet demonstrations, execute the following command (if you are still running the previous example, don't forget to kill it first):

> %JETTY_HOME%\bin\jetty.bat demo

Use your browser to go to the following location:

> http://localhost:8080

Select the Demonstrations link to explore the servlets provided. Here is page you should see.
Ant Quick Start
You must have Ant already installed to use this method. The following examples assume the current directory is $JETTY_HOME.

Running a simple server

To verify Jetty on your system, type the following command to start a very simple one-page server:

> Unix: `ant run`
> Windows: `ant.bat run`

To view the demo, use your browser to browse to `http://localhost:8080`

Running the Jetty demonstrations

To run the more sophisticated servlet demonstrations, execute the following command (if you are still running the previous example, don't forget to kill it first):

> Unix: `ant demo`
> Windows: `ant.bat demo`

To view the demonstrations, use your browser to go to `http://localhost:8080` and select the `Demonstrations` link to explore the servlets provided. This is the page you should see.

Running with JMX enabled

To run Jetty with JMX instrumentation, execute:

> Unix: `ant demo.jmx`
> Windows: `ant.bat demo.jmx`

Use your browser to visit the JMX agent view by browsing to `> http://localhost:8082`
Manual configuration and execution
Configuration
Jetty requires a Java 1.2 environment to be installed.
If you are using jdk1.4, you should use the path (or non-unix equivalent): `

      CLASSPATH=\
        $JETTY_HOME/lib/org.mortbay.jetty.jar:\
        $JETTY_HOME/lib/javax.servlet.jar:\
        $JETTY_HOME/ext/jasper-runtime.jar:\
        $JETTY_HOME/ext/jasper-compiler.jar:\
        $JETTY_HOME/ext/xercesImpl.jar

` For jdk1.2 or jdk1.3 us the following classpath, you need to use the alternative jetty jars and add the XML support. Thus the classpath to use is: `

      CLASSPATH=\
        $JETTY_HOME/lib/org.mortbay.jetty-jdk1.2.jar:\
        $JETTY_HOME/lib/javax.servlet.jar:\
        $JETTY_HOME/ext/jasper-runtime.jar:\
        $JETTY_HOME/ext/jasper-compiler.jar:\
        $JETTY_HOME/ext/xercesImpl.jar:\
        $JETTY_HOME/ext/xml-apis.jar:\
        $JETTY_HOME/ext/xmlParserAPIs.jar

` To use SSL you will also need to add the the jars below: (see here for more details):
`

             $JETTY_HOME/ext/jnet.jar  (not needed for JDK1.4.1)
             $JETTY_HOME/ext/jcert.jar
             $JETTY_HOME/ext/jsse.jar

`
To use JMX the classpath must also include: `

        $JETTY_HOME/ext/jmxri.jar
        $JETTY_HOME/ext/jmxtools.jar

`

To run JSP with the JDK compiler, you will also need to add the JDK `tools.jar` jar, and the ant.jar file from jakarta-ant 1.5 or later.

Execution
The execution examples are illustrated using Unix-style commands and environment variable specifications - adapt these as necessary to your environment.
To run a Jetty server, the steps are:
``

             cd $JETTY_HOME
             java org.mortbay.jetty.Server <xml configuration file>

The <xml configuration file> specifies the operation of the Jetty server. Some examples of these can be found in the $JETTY_HOME/etc directory.
For example, the simple one-page server mentioned in the Quick Start sections can be started by the following command:

> cd $JETTY_HOME
> java org.mortbay.jetty.Server etc/jetty.xml

The servlet demonstration server is run by the following:

> cd $JETTY_HOME
> java org.mortbay.jetty.Server etc/admin.xml etc/demo.xml

BACK | INDEX | EXIT | NEXT