Install Apache Tomcat Native

Steps to install apache tomcat native and its dependencies

If you are using Apache Tomcat in production then it would be good to install Apache Tomcat native library as it has some optimizations for production use. Below are the steps to install it. The steps were performed on an AWS EC2 instance (Amazon Linux), but should work on most of the linux systems.

  • If you are on an amazon box then login as root and change directory to /opt. This is where we will install the tomcat instance. For everyone else, use whatever user you want the tomcat to run as.
    sudo su -
    cd /opt
  • Download and Install Apache Tomcat

    Download apache tomcat. We will use using the 8.5.16 version. Extract it. The native source code is in the bin directory. Extract it as well.

    tar -xvf apache-tomcat-8.5.16.tar.gz
    cd apache-tomcat-8.5.16/bin/
    tar -xvf tomcat-native.tar.gz
  • The native library requires openssl and APR (Apache portable runtime). Lets install those. we will install them in a directory called /opt/softwares. You can install it in any directory that you like.

    cd /opt
    mkdir softwares
    cd softwares
  • Install Java (JDK) [/h2]

    cd /opt
    wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"
    sudo yum install -y jdk-8u141-linux-x64.rpm

  • Install the development tools for building the various libraries

    yum groupinstall "Development Tools"
  • Download and install openssl

    cd /opt/softwares
    tar -xvf openssl-1.0.2l.tar.gz
    cd openssl-1.0.2l
    ./config -fPIC --prefix=/opt/software/ --openssldir=/opt/software/
    make install
  • Install APR (Apache Portable Runtime)

    cd /opt/softwares/
    tar -xvf apr-1.6.2.tar.gz
    cd apr-1.6.2
    ./configure --prefix=/opt/software/
    make install
  • Install Tomcat Native

    cd /opt/apache-tomcat-8.5.16/bin/tomcat-native-1.2.12-src/native/
    ./configure --with-apr=/opt/software/ --with-java-home=/usr/java/jdk1.8.0_141/  --with-ssl=/opt/software/  --prefix=/opt/apache-tomcat-8.5.16
    make install
  • The last step is to set up the environment so that apache tomcat runtime can find the native libraries.
    Add the entries below into the file. A new file will be created if not present already.

    vi /opt/apache-tomcat-8.5.16/bin/
    export JAVA_HOME=/usr/lib/jvm/java-1.8.0
    export LD_LIBRARY_PATH

    Lets start the bean and see how it looks


    If all goes well, you should be able to see this in the output

    cat  /opt/apache-tomcat-8.5.16/logs/catalina.out | more
    09-Aug-2017 00:45:44.312 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.12] using APR version [1.6.2].
    09-Aug-2017 00:45:44.313 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
    09-Aug-2017 00:45:44.313 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
    09-Aug-2017 00:45:44.320 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2l  25 May 2017]

1 thought on “Install Apache Tomcat Native”

Leave a Comment