Install APR(Apache Portable Runtime) for Tomcat

My host's operating system is RedHat Enterprise. After I had installed Tomcat, I found the following logs in cataline.out when starting or stopping Tomcat:
Starting Tomcat:

Failed shutdown of Apache Portable Runtime

Stopping Tomcat:
The Apache Tomcat Native library which allows optimal performance in production environments was not found

The cause is that APR(Apache Portable Runtime) has not been installed. I took the following steps to resolve the issue.

Prerequisites for installing APR

APR support requires three main native components to be installed:

  • APR library
  • JNI wrappers for APR used by Tomcat (libtcnative)
  • OpenSSL libraries
  • Because OpenSSL had already been installed on my host, only the first two components were to be installed.



    What is APR

    The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations. The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behaviour regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.

    In fact, I don't know why APR is needed. I use Tomcat as a container for my applications implemented with Java which is portable among different operating systems. The roles of APR should be studied later.



    Download and Install APR core

    APR core 1.3.3 was downloaded from Apache's site. The package is apr-1.3.3-tar.gz.

    After extracting the package, the following steps were taken(refer to [2]):

    1. ./configure
    2. make
    3. make install (root is required)

    As a result APR libraries were installed in /usr/local/apr.



    Download and install JNI wrapper

    In Tomcat's binary package, there is a source code package bin/tomcat-native.tar.gz. After extracting it, the following steps were taken:

    1. cd tomcat-native-1.1.12-src/jni/native
    2. ./configure --with-apr=/usr/local/apr
    3. make
    4. make install(root is required)

    As a result tcnative libraries were installed in /usr/local/apr/lib



    Use APR libraries

    Tomcat should be told where to find APR libraries. I guess there are a few ways to tell it. I take the following way:

    Add a new environment variable to the Linux user who starts Tomcat server.

    CATALINA_OPTS=-Djava.library.path=/usr/local/apr/lib

    After all had been done, the following log messages were found when starting Tomcat:
    Sep 30, 2008 4:32:55 PM org.apache.coyote.http11.Http11AprProtocol start
    INFO: Starting Coyote HTTP/1.1 on http-8080
    Sep 30, 2008 4:32:55 PM org.apache.coyote.ajp.AjpAprProtocol start
    INFO: Starting Coyote AJP/1.3 on ajp-8009

    The following log messages were found when stopping Tomcat:
    Sep 30, 2008 4:27:06 PM org.apache.coyote.http11.Http11AprProtocol destroy
    INFO: Stopping Coyote HTTP/1.1 on http-8080
    Sep 30, 2008 4:27:06 PM org.apache.coyote.ajp.AjpAprProtocol destroy
    INFO: Stopping Coyote AJP/1.3 on ajp-8009

    APR was installed successfully.

THANKS

Thank you so much, you are a life saver!