Over a million developers have joined DZone.

Ubuntu: Installing Apache Portable Runtime (APR) for Tomcat

· Java Zone

Discover how AppDynamics steps in to upgrade your performance game and prevent your enterprise from these top 10 Java performance problems, brought to you in partnership with AppDynamics.

After reading “Introducing Apache Tomcat 6″ presentation by Mladen Turk I decided to enable Apache Portable Runtime (APR) native library for Tomcat. It was supposed to be as easy as

sudo ./configure
sudo make
sudo make install

but as you may guess, it was a little bit more than that.

1.
Installing Apache APR.

“Most Linux distributions will ship packages for APR” – those of Linode don’t, I had a barebone Ubuntu 10.10 box without even "gcc" and "make", let alone Apache APR. Thanks God, networking was not an issue, unlike last time.

wget http://apache.spd.co.il//apr/apr-1.4.2.tar.gz
tar -xzf apr-1.4.2.tar.gz
rm apr-1.4.2.tar.gz
cd apr-1.4.2/
sudo apt-get install make
sudo ./configure
sudo make
sudo make install

 
2. Installing Tomcat Native.

wget http://off.co.il/apache//tomcat/tomcat-connectors/native/1.1.20/source/tomcat-native-1.1.20-src.tar.gz
tar -xzf tomcat-native-1.1.20-src.tar.gz
rm tomcat-native-1.1.20-src.tar.gz
cd tomcat-native-1.1.20-src/jni/native
sudo ./configure --with-apr=/usr/local/apr

The result was

checking build system type... x86_64-unknown-linux-gnu
..
checking for APR... yes
..
checking for JDK location (please wait)... checking Try to guess JDK location...
configure: error: can't locate a valid JDK location

Ouch! "Can't locate a valid JDK location"? On my machine?

$ which java
/home/user/java/jdk/bin/java
$ echo $JAVA_HOME
/home/user/java/jdk
$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

But for some reason "tomcat-native-1.1.20-src/jni/native/configure" script didn’t see my "JAVA_HOME" variable no matter what and even installing "sun-java6-jdk" didn’t help much. After patching the "configure" script to dump locations it was looking for “valid JDK” I had:

..
configure: [/usr/local/1.6.1]
configure: [/usr/local/IBMJava2-1.6.0]
configure: [/usr/local/java1.6.0]
configure: [/usr/local/java-1.6.0]
configure: [/usr/local/jdk1.6.0]
configure: [/usr/local/jdk-1.6.0]
configure: [/usr/local/1.6.0]
configure: [/usr/local/IBMJava2-1.6]
configure: [/usr/local/java1.6]
configure: [/usr/local/java-1.6]
configure: [/usr/local/jdk1.6]
configure: [/usr/local/jdk-1.6]
..

Ok then, here you have it now:

sudo ln -s ~/java/jdk/ /usr/local/jdk-1.6
sudo ./configure --with-apr=/usr/local/apr
sudo make
sudo make install

And with

..
export LD_LIBRARY_PATH='$LD_LIBRARY_PATH:/usr/local/apr/lib'
..

I now had a beautiful log message in "catalina.out":

..
Mar 7, 2011 11:51:02 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.20.
Mar 7, 2011 11:51:02 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Mar 7, 2011 11:51:03 PM org.apache.coyote.AbstractProtocolHandler init
..

s soon as "evgeny-goldin.org" moves to its new location on the brand-new Linode box it will benefit from this performance optimization. I’ll describe the migration process and reasons for it a bit later, once it is done.

From http://evgeny-goldin.com/blog/ubuntu-installing-apr-tomcat/

The Java Zone is brought to you in partnership with AppDynamics. AppDynamics helps you gain the fundamentals behind application performance, and implement best practices so you can proactively analyze and act on performance problems as they arise, and more specifically with your Java applications. Start a Free Trial.

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}