The Apache Tomcat Native Library is an optional component for use with Apache Tomcat that allows Tomcat to use certain native resources for performance, compatibility, etc.

Specifically, the Apache Tomcat Native Library gives Tomcat access to the Apache Portable Runtime (APR) library’s network connection (socket) implementation and random-number generator. See the Apache Tomcat documentation for more information on how to configure Tomcat to use the APR connector.

准备工作

解压位于tomcat/bin目录下的apr源码

tar xzf tomcat-native.tar.gz

下载编译安装所需的依赖

dnf install apr-devel openssl-devel

Ubuntu

apt-get install libapr1.0-dev libssl-dev

CentOS

yum install apr-devel openssl-devel

配置编译参数

在tomcat-native/native目录下执行

1
2
3
4
./configure --with-apr=/usr/bin/apr-1-config \
--with-java-home=$JDK_HOME \
--with-ssl=yes \
--prefix=$CATALINA_HOME

执行成功后make && make install

编译后的文件会放到$CATALINA_HOME/lib下

如果Tomcat启动时还是找不到APR的话,在bin/setenv.sh中添加

1
JAVA_OPTS="-Djava.library.path="$CATALINA_HOME"/lib"