Jetty Tutorial for Beginners
In this article, we will give brief information about Jetty and provide examples of Java application deployment on Jetty. Our examples will consist of both standalone and Embedded modes of Jetty.
Jetty is a Servlet container and Web Server which is known to be portable, lightweight, robust, flexible, extensible and easy to integrate.
Jetty can be deployed as a standalone server and also can be embedded in an existing application. In addition to these, a Maven Jetty plugin is available in order to run applications in your development environment.
SPDY, WebSocket, OSGi, JMX, JNDI, JAAS are some of the technologies that Jetty integrates nicely.
Today, Jetty is widely used in many platforms both for development and production. Small to large enterprise applications. SaaS (such as Zimbra), Cloud Applications( such as Google AppEngine), Applications Servers(such as Apache Geronimo) and tools (such as SoapUI) are powered by Jetty.
Jetty is open source, hosted by Eclipse Foundation. Current version (as of June 2015) is 9.2.x. You can more detailed information on Jetty Home Page.
1.Jetty as a Standalone server
In the first part, we will configure Jetty as a Standalone Server.
1.1 Downloading and Installing Jetty
You can visit the downloads page and download the latest version (v9.2.11 currently) as an archive file in zip or tar.gz format. Size is about 13 MBs.
There is no installation procedure for Jetty. Just drop it to a folder as you wish and uncompress the downloaded archive file.
1.2 Prerequisites
The only prerequisite for Jetty 9 is having installed Java 7 in your environment. You can downgrade to Jetty 8 if you have Java 6. A complete Jetty-Java compatibility information can be viewed here.
1.3 Running Jetty
Running Jetty on the default configuration is as simple as following two steps:
- Navigate to the directory where you unpacked the downloaded archive. I will call it JETTY_HOME from now on.
- Run the following command:
java -jar start.jar
When Jetty starts running successfully; it produces the a line in the log similar to the following:
2015-06-04 14:27:27.555:INFO:oejs.Server:main: Started @11245ms
By default, Jetty runs on port 8080, but we will see how to configure it in the next sections of this tutorial.
You can also check via the browser typing http://localhost:8080 as the URL. You will see a 404 error, since no application is deployed in the root context.
The response is as below:

1.4 Changing the server port
As mentioned above, default port jetty is 8080. If you need to change it, you can apply following steps:
- Navigate to the JETTY_HOME.
- Open the start.ini file with a text editor.
- Navigate to the line where the parameter jetty.port is configured.
- Change the parameter to the desired port number.
- Start Jetty again.
In the following segment, we set the Jetty port to 7070 instead of 8080
## HTTP port to listen on jetty.port=7070
After we restart our server will run on port 7070.
1.5 Deploying Web Applications on Jetty
The procedure to deploy web applications on Jetty is as follows:
- Navigate to your JETTY_HOME folder.
- There is a directory named as webapps under JETTY_HOME. Navigate there.
- Drop your WAR file in that folder.
The application is initialized immediately, you do not need to restart Jetty since the webapps directory is continuously monitored by the server.
There are a sample web applications under JETTY_HOME/demo-base/webapps/. You can pick one of them(for example async-rest.war) and copy to the webapps directory. As you copy the WAR file, the application will be initialized.
When you type Download NOW!


