Jetty Web Server on CentOS 6

This short blog post explains how to install Jetty Web Server from the tar archive on Centos 6. 

Installing Jetty is quite straight forward and basically requires you to extract the tar archive to a location. You may then wish to create a separate system user to run the server. I chose to create a system user specifically for this task, it also helps restrict permissions.

Download Jetty 7 from the website I have decided to install Jetty located at /srv rather than /opt but you can install it anywhere you like. I ran the following commands to help with the installation.

cd /srv
tar zxf jetty-distribution-7.4.5.v20110725.tar.gz
ln -s jetty-distribution-7.4.5.v20110725 jetty

The last command just creates a link from the directory jetty to the directory created when you extracted the tar archive. Next I shall show you how to create a user to run Jetty with. You can also make it run on startup automatically so that when you reboot you do not need to start it.

adduser -r -m jetty
chown -R jetty:jetty /srv/jetty
cd /etc/init.d
ln -s /srv/jetty/bin/ jetty
chkconfig --add jetty
chkconfig --level 345 jetty on

You will need to add some values so that Jetty can find your default java install and to set the port which you wish to add jetty to. You can add these values to either or /etc/default/jetty which is the preferred way of configuring applications on Linux.

JAVA_HOME=/usr/java/default <--- your location to java 
JAVA_OPTIONS=" -server -Xms256m -Xmx1024m -XX:+DisableExplicitGC " 
JETTY_PORT=8080 <-- port number change if you need to 
JETTY_HOST= <--- If you don't set this to, jetty only listen on localhost 

You should now be able to start Jetty freely with the following command.

service jetty start

Jetty should start without any problems and you can add your own web applications to jetty. If you have any problems check the log files located in /srv/jetty/logs.

Feel free to leave a comment.