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 3 ways to run it:
- using prepared scripts
- using the Ant build environment
- manually
The scripts handle all the housekeeping tasks associated with getting
a server started, and are provided as Unix shell scripts
and as Window bat files (you should treat
them as examples, and feel free to brew your own). Alternatively, if you
have Ant installed, you can use it to run the demonstration
content. Finally, you can manually configure your
environment and run the server by hand.
Quick start on Unix
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.
Quick start on Windows
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.
Unix
Set the fundamental Jetty evironment variable
$JETTY_HOME:
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:
ant -buildfile $JETTY_HOME/build.xml run
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):
ant -buildfile $JETTY_HOME/build.xml 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
Set the fundamental Jetty evironment variable
%JETTY_HOME%:
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:
ant.bat -buildfile %JETTY_HOME%\build.xml run
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):
ant.bat -buildfile
%JETTY_HOME%\build.xml
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.
Manual configuration and execution
Configuration
Jetty requires a Java 1.2 environment to be installed.
The $CLASSPATH
variable (or its non-Unix equivalent) must have the following set as
a minimum:
CLASSPATH=\
$JETTY_HOME/lib/org.mortbay.jetty.jar:\
$JETTY_HOME/lib/javax.servlet.jar:\
$JETTY_HOME/lib/javax.xml.jaxp.jar:\
$JETTY_HOME/lib/org.apache.jasper.jar:\
$JETTY_HOME/lib/org.apache.crimson.jar
To use SSL you will also need to add the the jar below, which is
a merge of the jsse, jnet and jcert jars from the JSSE package
(see here for more details):
$JETTY_HOME/lib/com.sun.net.ssl.jar
To run JSP with the JDK compiler, you will also need to add the
jar containing the JDK compiler (if you wish to use another compiler
you will have to configure jasper):
$JDK_HOME/lib/tools.jar
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 as following:
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