Installing Java 8 and Tomcat 8 on Debian Jessie or Raspbian or RedHat

Apache Tomcat is a Servlet/JSP container and version 8.0 implements the Servlet 3.1 and JavaServer Pages 2.3 specifications. Please note that Apache Tomcat 8.0 requires a Java Standard Edition Runtime Environment (JRE) version 7 or later. So we start with installing a recent version of Oracle’s JRE.

Install Oracle JRE 8 on Debian Linux (or Raspbian)

To install Oracle’s Java Runtime with apt-get, we first need to entend the list of apt-get’s sources. Once that is done, an java-installer will actually install the Java SE Runtime Environment. Here are the steps to follow:

As I’m writing this, the newly installed Java Runtime reports its version as 1.8.0_101:

With Java now installed we move on, installing Tomcat. However, it may be beneficial to have an dedicated user for Tomcat.
BTW, Java got installed into this location: /usr/lib/jvm/java-8-oracle

.. which should result in something like this:

Installing Tomcat 8.5.x

To make it easy to replace this release with future releases, we are going to create a symbolic link that we are going to use when referring to Tomcat (after removing the old link, you might have from installing a previous version):

Since we created a tomcat user, he should also own all these files in

If Tomcat’s default HTTP port (8080) is already in use, you need to edit the server.xml configuration file, e.g.
edit /usr/share/tomcat/conf/server.xml and replace 8080 with 8000

Starting Tomcat

Stopping Tomcat

Staring Tomcat when the server boots

To start Tomcat automatically, every time the server re-boots, save this script in /etc/init.d/tomcat

Now change the permissions of the newly created file and add the correct symlinks automatically:

Long Startup Time
Tomcat relies heavily relies on the SecureRandom class to provide random values, for instance to generate session ids. During startup, if entropy source that is used to initialize SecureRandom is short of entropy, this can lead to very long delays, which can be confirmed in the logs/catalina.out log file. Adding JAVA_OPTS="-Djava.security.egd=file:/dev/urandom" at the beginning of the bin/catalina.sh file, will significatinly speedup the startup time.

RedHat

While not my preferred Linux distribution, RedHat and CentOS are the standard in Corporate America.  So here are a few comments on how to install Java and Tomcat on RedHat:

Installing Java 8

This will install Oracle’s Java 8 or more specifically Java(TM) SE Runtime Environment (build 1.8.0_51-b16) and Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode) here: /usr/java/jdk1.8.0_51/

Later, if you decide to run Tomcat on port 80, you will also need to execute this:

and cat this content

into /etc/ld.so.conf.d/java.conf

Creating a Tomcat User account

useradd -r -m tomcat
passwd -l tomcat

 

Creating a service script

/etc/systemd/system/tomcat.service

 

  • sudo systemctl daemon-reload
  • sudo systemctl enable tomcat
  • sudo systemctl start tomcat

 

One Reply to “Installing Java 8 and Tomcat 8 on Debian Jessie or Raspbian or RedHat”

  1. Nicely done! Thanks

Leave a Reply