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.
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.
Next we need to create a system user for jetty. The folder /opt/jetty needs to be owned by that user.
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 .
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.
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.
You can verify the configuration of jetty using any of the following methods. Both displays the same output.
You can confirm that jetty is running as follows. IF jetty is running, it will show the jetty commands in use.
Once everything is running fine, set jetty to automatically start on boot.