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:

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):

1

2

$sudo rm-f/usr/share/tomcat

$sudo ln-s/usr/share/apache-tomcat-8.5.5/usr/share/tomcat

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

1

2

$sudo chown-Rtomcat:tomcat/usr/share/tomcat/*

$sudo chmod+x/usr/share/tomcat/bin/*.sh

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

1

2

3

4

5

6

7

$sudo/bin/su-tomcat-c/usr/share/tomcat/bin/startup.sh

Using CATALINA_BASE:/usr/share/tomcat

Using CATALINA_HOME:/usr/share/tomcat

Using CATALINA_TMPDIR:/usr/share/tomcat/temp

Using JRE_HOME:/usr

Using CLASSPATH:/usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar

Stopping Tomcat

1

2

3

4

5

6

7

$sudo/bin/su-tomcat-c/usr/share/tomcat/bin/shutdown.sh

Using CATALINA_BASE:/usr/share/tomcat

Using CATALINA_HOME:/usr/share/tomcat

Using CATALINA_TMPDIR:/usr/share/tomcat/temp

Using JRE_HOME:/usr

Using CLASSPATH:/usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar

Staring Tomcat when the server boots

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

#!/bin/bash

### BEGIN INIT INFO

# Provides: tomcat

# Required-Start: $network

# Required-Stop: $network

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: Start/Stop Tomcat server

### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

start(){

/bin/su-tomcat-c/usr/share/tomcat/bin/startup.sh

}

stop(){

/bin/su-tomcat-c/usr/share/tomcat/bin/shutdown.sh

}

case$1in

start|stop)$1;;

restart)stop;start;;

*)echo"Run as $0 &lt;start|stop|restart&gt;";exit1;;

esac

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

1

2

chmod755/etc/init.d/tomcat

update-rc.dtomcat defaults

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: