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 http://www.eclipse.org/jetty/. 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 wget http://download.eclipse.org/jetty/7.4.5.v20110725/dist/jetty-distribution-7.4.5.v20110725.tar.gz 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.sh 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 jetty.sh or /etc/default/jetty which is the preferred way of configuring applications on Linux.
JAVA_HOME=/usr/java/default <--- your location to java JAVA=$JAVA_HOME/bin/java JAVA_OPTIONS=" -server -Xms256m -Xmx1024m -XX:+DisableExplicitGC " JETTY_HOME=/srv/jetty JETTY_USER=jetty JETTY_PORT=8080 <-- port number change if you need to JETTY_HOST=0.0.0.0 <--- If you don't set this to 0.0.0.0, jetty only listen on localhost JETTY_LOGS=/srv/jetty/logs/
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.