Adding APR support for Tomcat 6
Tomcat 6 has some neat new features. The one feature I am eyeballing the most is it's advanced IO features like the Comet Servlet Interface. In an upcoming article I'll be explaining the Comet Servlet Interface some more, Plus a neat proof of concept!
In order to get these advanced IO features, one has to enable APR listener support. APR is Apache's portable runtime that gives developers an API which behavior is consistent across many platforms. This runtime is the magic that makes the latest versions of Apache's httpd so darn portable. It's also needed for some advanced features in Tomcat!
I am assuming you have tomcat 6 installed at this point and are trying to figure out how to get APR working. I am also assuming you are running Linux (If not you better!). To install APR support you need JNI headers, OpenSSL, and of course the APR lib. If you have a Java JDK 1.4+ installed on your system, the JNI headers should already be there. If you don't have this, go to the Java web site, grab the latest JDK, install it, and point your JAVA_HOME environment variable at it. Depending on your distribution, you may have to do some other voodoo to get your default Java switched over. For me all I had to do was move a symlink. Most likely you already have OpenSSL libs installed on your Linux Distribution, you might need to grab the headers so that you can compile against the libraries, usually these are in a package named such as libssl-dev. You'll also need the APR library and headers. Some distributions already have APR available through packages. Go check your package repos and install libapr and libapr-dev packages. For me, I had to install APR from the source packages here. You Should only have to do the familiar ./configure && make && make install, to install APR from source.
Now that we got the deps out of the way, time to get APR working in Tomcat. First thing we need to do is compile the JNI wrappers. The source for this comes with Tomcat, cd into your Tomcat $CATALINA_BASE/bin/ directory, and do the following: (paths may vary)
tar -xvzf tomcat-native.tar.gz cd tomcat-native-1.1.10-src/jni/native ./configure --with-apr=/usr --with-java-home=/usr/lib/java --with-ssl=yes make sudo make install
After the make install it should give the path where the wrappers were installed, for me they were in /usr/local/apr/lib/. Now the hard part was getting Java to find these wrappers, since they are not in the usual java.library.path. To get them in the java.library.path, set the LD_LIBRARY_PATH environment variable on server startup. Edit tomcat's startup.sh script and add a line near the beginning (I did mine after the uname case stuff).
export LD_LIBRARY_PATH=/usr/local/apr/lib
Restart Tomcat and enjoy! You will be able to tell that APR support is installed by going to your /manager/status webapp, there should be a new section called 'OS' that gives OS memory and CPU information.
RSS 1.0 Feed





Comments
I'm using RedHat Linux and had to build APR from source code. I ran into an obstacle and it took a while to find the solution.
The symptom of the problem was that Tomcat would start up very slowly. It seemed to hang for a minute or so before coming up.
The solution was to add an argument to the configure command when building APR:
configure --with-devrandom=/dev/urandom
ss
http://www.jyog.com