Evgeny Goldin works as a Technical Evangelist for the JetBrains TeamCity CI build server. He speaks Java, JavaScript, Perl and Groovy. His favorite products are MediaWiki, Intellij IDEA, Git, Artifactory, Gradle, YouTrack and TeamCity. He enjoys driving, learning and solving challenging problems. He doesn't like wasting time and being unproductive and believes that simplicity, attention to details and tidy working environments are the most efficient approaches to successful delivery. Evgeny is a DZone MVB and is not an employee of DZone and has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

Ubuntu: Installing Apache Portable Runtime (APR) for Tomcat

  • submit to reddit

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.

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
$ echo $JAVA_HOME
$ 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/

Published at DZone with permission of Evgeny Goldin, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Jose Paz replied on Wed, 2011/03/09 - 10:11am

isn't it the same to just: sudo apt-get install libtcnative-1 is there any difference?

Will Ezell replied on Wed, 2011/03/09 - 9:24pm

Did you try : apt-get install libtcnative-1 ?? I think it has what you need without the need for automake and gcc ?

Evgeny Goldin replied on Thu, 2011/03/10 - 7:43am in response to: Will Ezell

No, I didn't know about it but a reader on a blog already pointed that out. Seems to be an obvious thing that I missed. Will know it for future setups, thanks!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.