Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Tomcat Native Library

This article deals with the use of the Apache Tomcat Native Library to speed up Liferay.

Basic Overview #

The Apache Tomcat Native Library is a JNI (Java Native Interface) that provides many of Tomcat's core functionality in native code instead of Java bytecode. What does this mean? SPEED. For a cursory speed comparison, here is the startup time for my Liferay running on Tomcat without it installed:

 INFO: Server startup in 14463 ms

And, with the native library installed:

 INFO: Server startup in 13266 ms

That's about a 10% speed boost. If you do not have the native library properly installed on your system, your log files will always begin with something that looks like this:

 INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

Installation #

Linux #

(Tested with standard Tomcat 5.5.17 downloaded from Apache site, running on Ubuntu 7.04 - Feisty Fawn)

  1. Make sure that you have the libssl-dev and libapr1-dev packages installed$ apt-get install libssl-dev libapr1-dev
  2. Switch to your tomcat's bin directory$ cd ${TOMCAT_HOME}/bin
  3. Extract the tarball (tarred and gzipped archive) of the tomcat native lib$ tar -xvzf tomcat-native.tar.gz
  4. Jump into the source folder$ cd tomcat-native-1.1.3/jni/native
  5. Configure, make and install it$ ./configure --with-apr=/usr && make && sudo make install
  6. Change to the system library folder$ cd /usr/lib
  7. Make a convenience link to you new library$ sudo ln -s /usr/local/apr/lib/
  8. Edit ${TOMCAT_HOME}/bin/ adding the following lines somewhere before the java program is executedLD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATHexport LD_LIBRARY_PATH
  9. Finally, edit /etc/modprobe.d/aliases and change the linealias net-pf-10 ipv6toalias net-pf-10 off ipv6 and reboot. This disables IPV6 which the library does not support yet (and hence will throw exceptions when trying to bind to TCP ports on network devices having IPV6 enabled).
  10. Restart tomcat and enjoy!

Mac OS X #

  • Make sure to have installed the latest version of MacPorts.
  • From the Terminal program, install and make symbolic links of the native libraries:
sudo port install tomcat-native
sudo ln -s /opt/local/lib/libtcnative-1.* /usr/lib/java
  • Restart Tomcat and enjoy!

Windows #

  1. Download
  2. Copy tcnative-1-ip4.dll to %TOMCAT_HOME%/bin
  3. Restart Tomcat and enjoy!

JBoss-Tomcat Bundle #

If you are running with JBoss-Tomcat, be aware that the standard APR will not work properly. This is because JBoss makes some modifications to the Tomcat that is part of its bundle. For instructions on how to install the native libraries for JBoss-Tomcat, see the documentation at Liferay running on JBoss AS 4.0.5 has been reported to run with JBoss Native 2.0.1 performing, under load, with about a 20% speed boost.

0 Attachments
Average (5 Votes)
The average rating is 4.8 stars out of 5.
Threaded Replies Author Date
This is a fantastic article. I followed these... Ahmed Hasan February 27, 2010 6:10 AM

This is a fantastic article. I followed these steps to set up APR native tomcat in our of our LINUX based production servers. Just few minor points i would like to highlight, so that i can help people like me.

1. In step 5, it may give the problem - "Unable to find JDK". In your command prompt, give "export JAVA_HOME=/usr/liv/jvm/java-6-sun"

2. Step no 8, insert the following line in your "" under "tomcat/bin",


3. In step 9, you may NOT find the file aliases. Do the following steps,

a. touch /etc/modprobe.d/aliases
b. vi /etc/modprobe.d/aliases
c. insert the line, "alias net-pf-10 off ipv6"
d. save and close the file

4. Re-boot the server with the command "init 6"

5. After reboot, start your tomcat.
Posted on 2/27/10 6:10 AM.