Home > Support > HOWTO List > JSP Hosting: Jetty

Jetty Servlet Engine

Jetty is very reliable, fast and uses minimal memory and CPU.  Jetty supports the (most recent) 2.3 Servlet specification and 1.2 JSP specification.  Plans are under way for it to support the JSP 2.0 specification when it arrives.  Jetty supports 'WAR' files, and speedily serves up JSP and static content.

In addition to the server software, we have pre-installed a number of common Java libraries.  They include Ant, Crimson, Xalan, Xerces, BCEL, and Jasper.

Jetty Installation

RimuHosting pre-installs the Jetty Servlet engine on its RedHat VPS plans.  For those that want to do it themselves, here is a rough guide...

The Jetty install, from the sourceforge.net files is via a tar.gz file.  The following steps will put the Jetty files in the 'appropriate' directories.  For example, put the logs in /var/log/jetty, and the config files in /etc/jetty.

Note the following steps are CentOS/RHEL specific, although with a few tweaks they should work on other distros as well


cd /opt
# Select the file you want to use from here: 
# http://sourceforge.net/project/showfiles.php?group_id=7322
# VERSION will be used as a variable in the next few commands
VERSION=Jetty-4.2.10pre0

# wget "http://heanet.dl.sourceforge.net/sourceforge/jetty/$VERSION.tar.gz"
# extract the tar file
tar xzvf $VERSION.tar.gz

# create some links
ln -sf /opt/$VERSION /opt/jetty

# pop a link to the 'init' script in the standard RedHat location
ln -sf /opt/jetty/bin/jetty.sh /etc/init.d/jetty

# make it so that /usr/local/jdk points to your current Java setup
ln -sf /usr/java/j2sdk1.4.1_02 /usr/local/jdk
cd /opt/jetty

# create a jetty user
groupadd -r -f jetty
useradd -r -s /sbin/nologin -d /opt/jetty --gid jetty jetty

# edit bin/jetty.sysvinit to use a --user=jetty on the daemon calls
# (no point jetty running as root, eh?)
chown -R jetty.jetty /opt/jetty

#Add "export JAVA_HOME=/usr/local/jdk" to bin/jetty.sh
chmod +x bin/*.sh
chmod +x /etc/init.d/jetty
mkdir -p /var/log/jetty

# make it so that logs end up in /var/log/jetty
rm -rf logs
ln -s /var/log/jetty logs

# make it so the conf files are in /etc/jetty
mv etc /etc/jetty
ln -s /etc/jetty etc

Jetty Installation Part II

The following steps are not yet part of the standard install.  If you are going to run Jetty on your RimuHosting VPS, please follow them.

Create a logrotate file for Jetty so that you logs don't keep getting larger and larger:


echo "/var/log/jetty/*.log {
copytruncate
weekly
rotate 52
compress
missingok
}" > /etc/logrotate.d/jetty

Running Jetty on Startup

By default RimuHosting does not enable Jetty on server startup.  However, it is easy enough to do.

Turn on the service for bootup: chkconfig --add jetty && chkconfig --level 35 jetty on

And start the service: /etc/init.d/jetty start

You will probably want to disable Apache: chkconfig --del httpd

Check jetty is running:  http://yourserverip:8080

The logs are in /var/log/jetty.  The config files are in /etc/jetty.

To deploy a WAR file, pop it in /opt/jetty/webapp.

Jetty runs under the 'jetty' user. So if you edit any of the files in there, do so as jetty. Also, if you upload war files, make sure they are readable by the jetty user.

If you need to redirect regular http (port 80) traffic to jetty without running another web server in front then try the following command since running any user program on low port numbers on *nix systems is generally blocked, as low port numbers are protected and only accessible as the root user. {code}iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080{code}.