web analytics

Installing Jetty in Ubuntu 14.04

Jetty is a java web server like tomcat, and java servlet container. This post describes how to install the latest version of Jetty in Ubuntu.

Latest version of Jetty can be downloaded from http://download.eclipse.org/jetty/stable-9/dist/

Jetty requires java and hence the first step is to install java. The latest version of Jetty, as of this writing is Jetty 9.3.8. Check the link here which shows what version of Java is required for the version of Jetty you are installing. If the version of Java does not match the version in which Jetty is compiled, then it will result in version conflict and Jetty will fail to start.

I am going to install Jetty 9.3.8, hence I need JVM 1.8. Login to your ubuntu machine and switch to root. Then issue the following commands to install java in the server.

[root@test ~]# apt-get install openjdk-8-jdk

[root@test ~]# mkdir /usr/java

[root@test ~]# ln -s /usr/lib/jvm/java-8-openjdk-amd64 /usr/java/default


Now java is installed in the server which you can confirm by executing the command java -version

We are going to download the latest version of jetty from the server now. The tar.gz file which is downloaded needs to be renamed correctly. After that unzip the file and rename the extracted folder as jetty.

[root@test ~]# cd /opt/

[root@test ~]# wget http://eclipse.org/downloads/download.php?file=/jetty/stable-9/dist/jetty-distribution-9.3.8.v20160314.tar.gz&r=1

[root@test ~]# mv download.php\?file\=%2Fjetty%2Fstable-9%2Fdist%2Fjetty-distribution-9.3.8.v20160314.tar.gz\&r\=1    jetty-distribution-9.3.8.v20160314.tar.gz

[root@test ~]# tar -xzvf   jetty-distribution-9.3.8.v20160314.tar.gz

[root@test ~]# mv  jetty-distribution-9.3.8.v20160314.tar.gz    jetty

Next we need to create a system user for jetty. The folder /opt/jetty needs to be owned by that user.

[root@test ~]# useradd jetty -U -s /bin/false
[root@test ~]# chown -R jetty:jetty /opt/jetty


Now, we will run jetty as a service and create a startup script for it so that we can easily start, stop and restart the service. For that copy the file jetty.sh to /etc/init.d/jetty .

[root@test ~]# cp /opt/jetty/bin/jetty.sh /etc/init.d/jetty

Now, create a file /etc/default/jetty which will serve as the settings file or something like a config for jetty. The values for java path, jetty home directory, jetty port, jetty user, jetty home directory etc will be taken from this file.

[root@test ~]# vi /etc/default/jetty           # add the following lines to it

JAVA=/usr/bin/java # Path to Java
NO_START=0 # Start on boot
JETTY_HOST= # Listen to all hosts
JETTY_USER=jetty # Run as this user

You can choose any port that you like, only that it should not be currently in use by any other service. Now we can start the jetty service, just like any other service.

[root@test ~]#/etc/init.d/jetty start

You can verify the configuration of jetty using any of the following methods. Both displays the same output.

[root@test ~]#/etc/init.d/jetty check


[root@test ~]# /etc/init.d/jetty status

You can confirm that jetty is running as follows. IF jetty is running, it will show the jetty commands in use.

[root@test ~]#ps aux | grep jetty


Once everything is running fine, set jetty to automatically start on boot.

[root@test ~]# update-rc.d jetty defaults

2 comments to Installing Jetty in Ubuntu 14.04

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>