在 java.library.path 中找不到基于 APR 的 Apache Tomcat Native 库,该库可在生产环境中实现最佳性能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42871924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 06:55:58  来源:igfitidea点击:

The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path

javatomcatintellij-ideaservercatalina

提问by s-n-2

When I debug tomcat, the broswer start but get 404:

当我调试 tomcat 时,浏览器启动但得到 404:

HTTP Status 404 - /

type Status report

message /

description The requested resource is not available.

Apache Tomcat/7.0.75

HTTP 状态 404 - /

类型状态报告

信息 /

描述 请求的资源不可用。

Apache Tomcat/7.0.75

The Tomcat Catalina Log and Server Log all have this below error:

Tomcat Catalina 日志和服务器日志都有以下错误:

The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/luowensheng/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.

在 java.library.path:/Users/luowensheng/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/扩展名:/System/Library/Java/Extensions:/usr/lib/java:.

I searched SO, find a similar post:

我搜索了SO,找到了一个类似的帖子:

What does "The APR based Apache Tomcat Native library was not found" mean?

“未找到基于 APR 的 Apache Tomcat 本机库”是什么意思?

My software environment is:

我的软件环境是:

Mac OS 
IntelliJ IDEA

回答by Ghayel

HTTP Status 404 - /

HTTP 状态 404 - /

This error is caused due to many problems for example:

此错误是由许多问题引起的,例如:

  1. Mostly this error is thrown due to invalid path. make sure the following folders exists:
  1. 大多数情况下,由于路径无效而引发此错误。确保存在以下文件夹:
>  $cataline_home/webapps/your-project|
>                                         -->html,css,images, etc.                                       
>                                         -->WEB-INF|
>                                                    -->classes (your java files)
>                                                    -->lib     (your libraries)
>  $cataline_home/webapps/your-project|
>                                         -->html,css,images, etc.                                       
>                                         -->WEB-INF|
>                                                    -->classes (your java files)
>                                                    -->lib     (your libraries)
  1. Make sure java is install on your machine. You can check it by running simply javacon command prompt or using java -version
  2. You are typing wrong URL address or incomplete URL or URL without tomcat port
  3. Also make sure you added your classes properly in web.xml file
  1. 确保您的机器上安装了 java。您可以通过javac在命令提示符下运行或使用 java -version来检查它
  2. 您输入了错误的 URL 地址或不完整的 URL 或没有 tomcat 端口的 URL
  3. 还要确保您在 web.xml 文件中正确添加了类

installing Tomcat APR in MAC is HEREand for Linux following is tested by myself

在 MAC 中安装 Tomcat APR 在这里,对于 Linux 以下是我自己测试的

INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path

信息:在 java.library.path 中找不到基于 APR 的 Apache Tomcat Native 库,该库可在生产环境中实现最佳性能

Prerequisites for installing APRAPR library APR-util library OpenSSL library

安装 APR 的先决条件APR 库 APR-util 库 OpenSSL 库

yum install openssl-devel
yum groupinstall "Development Tools"

mkdir tomcat-apr
cd tomcat-apr
wget http://www.us.apache.org/dist//apr/apr-1.5.2.tar.gz
tar -zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure
make
make install

The default installation path is /usr/local/apr

默认安装路径为/usr/local/apr

Download and Install APR-util                  
wget http://www.eu.apache.org/dist//apr/apr-util-1.5.4.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --with-apr=/usr/local/apr
make
make install

The default path of installation is /usr/local/apr/lib Install JNI Wrapper for APR used by Tomcat (libtcnative)

安装默认路径为/usr/local/apr/lib 安装Tomcat使用的APR的JNI Wrapper (libtcnative)

cd $CATALINA_HOME/bin
tar -zxvf tomcat-native.tar.gz
cd tomcat-native-1.1.29-src/jni/native
./configure --with-apr=/usr/local/apr --with-java-home=/var/java/jdk1.7.0_45
make
make install

The native libraries were installed in /usr/local/apr/lib Integrate APR with Tomcat There are two ways to set Tomcat integrate with APR.

本地库安装在/usr/local/apr/lib 将APR 与Tomcat 集成 Tomcat 与APR 集成有两种方法。

One is you can add the following parameter when start up the Tomcat in bin/catalina.sh: CATALINA_OPTS="-Djava.library.path=/usr/local/apr/lib"

一种是在bin/catalina.sh中启动Tomcat时可以添加如下参数:CATALINA_OPTS="-Djava.library.path=/usr/local/apr/lib"

The other is to add a new environment variable LD_LIBRARY_PATH in /etc/profile:

另一种是在/etc/profile中添加一个新的环境变量LD_LIBRARY_PATH:

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

Then makes it effect via:

然后通过以下方式使其生效:

source /etc/profile 

After restarting the Tomcat service, we can get the following message in catalina.out log if APR was installed successfully.

重启Tomcat服务后,如果APR安装成功,我们可以在catalina.out日志中看到如下信息。

Oct 07, 2015 8:08:54 AM org.apache.catalina.core.AprLifecycleListener init INFO: Loaded APR based Apache Tomcat Native library 1.1.29 using APR version 1.5.2. Oct 07, 2015 8:08:54 AM org.apache.catalina.core.AprLifecycleListener init INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].

2015 年 10 月 7 日上午 8:08:54 org.apache.catalina.core.AprLifecycleListener init INFO:使用 APR 版本 1.5.2 加载基于 APR 的 Apache Tomcat Native 库 1.1.29。2015 年 10 月 7 日上午 8:08:54 org.apache.catalina.core.AprLifecycleListener init INFO:APR 功能:IPv6 [true]、sendfile [true]、接受过滤器 [false]、随机 [true]。