MacOS下Tomcat-native-APR警告问题

最近在学习 JavaWeb 需要要用到服务器,果断安装 Tomcat,安装完成后发现在 IntelliJ Idea 中启动时老是会出现如下警告:The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:…查阅和参考了一大坨资料后总结一下解决方法。

1. 下载并编译 APR

  下载 APR

  在终端编译 APR

1
cd /<your_apr_dir>/aprCFLAGS='-arch x86_64' ./configuremakesudo  make install

2. 下载并编译 APR-util

  下载 APR-util

  在终端编译 APR-util

1
cd /<your_apr-util_dir>/apr-utilCFLAGS='-arch x86_64' ./configure --with-apr=/usr/local/apr/bin/apr-1-configmakesudo make install

3. 安装 OpenSSL

  安装 OpenSSL 之前首先需要在 Homebrew 安装 Homebrew.

  安装完成后打开终端输入下面命令

1
 brew install openssl

  编译 Tomcat native 库

  Tomcat native 库已经提供在下载好的 Tomcat 中了. 我下载的 Tomcat 版本是 apache-tomcat-8.5.27, 其中 jdk 的路径需要自行更换

1
cd /<your_tomcat_dir>/bingunzip tomcat-native.tar.gztar xf tomcat-native.tarcd /<your_tomcat-native_dir>/nativeCFLAGS='-arch x86_64' ./configure --with-apr=/usr/local/apr --with-ssl=/usr/local/opt/openssl --with-java-home=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Homemakesudo make install

  配置 Tomcat 关联路径

1
sudo ln -s /usr/local/apr/lib/libtcnative-1.dylib /Library/Java/Extensions/

  在 IntelliJ idea 中启动 Tomcat,如果看到下面的提示则证明 APR 安装成功.

1
2
3
17-Jul-2018 09:43:24.134 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].

17-Jul-2018 09:43:24.134 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]