If you look around on the internet you may find a lot of blogs guiding you on the installation of Jetty in RHEL 7 (or CentOS) which require you to download a new fresh distribution of Jetty tarball.

Since Jetty is already packaged in RHEL 7, I’d rather use the packaged version instead of adding a new piece of software which I would need to maintain afterwards.

Below the procedure I’ve applied to get a working Jetty deployment integrated with systemd with multi instance support (that is you can deploy more instances of Jetty if you need to).

As a first step you need to install the Jetty packages. Being a highly modular design, you can select which modules (packages) you need depending on the kind of application you’re going to deploy. In my case I had a fairly simple war to deploy – needing PostgreSQL connectivity and JNDI – so these packages did the job:

yum install jetty-runner jetty-start jetty-deploy postgresql-jdbc

Then download the jetty@.service systemd unit file and place it in the /etc/systemd/system directory, then make systemd aware of the new file:

systemctl daemon-reload

Now you can prepare your Jetty environment in /etc/jetty/instance_name

This one should contain at least an etc directory, were the jetty confs reside, a webapps directory were you’ll deploy your wars and a lib/ext directory which you can use optionally to add jars to the instance classpath – in my case I’ve dropped a symlink there to link PostgreSQL’s JDBC3 driver at /usr/share/java/postgresql-jdbc3.jar.

I’ve provided a instance_template tarball that you can use as a starting point.

Alternatively you can always download the jetty distribution (matching the same version as RHEL’s package) and copy its etc directory to use as a template in your instance directory.

When the instance environment is ready you can start it via:

systemctl start jetty@INSTANCE_NAME

To have Jetty started at boot you can enable an instance:

systemctl enable jetty@instance_name

You can track the status of Jetty using the standard systemd commands:

systemctl status jetty@instance_name

Enjoy your packaged jetty!