在 java.library.path 上找不到基于 APR 的 Apache Tomcat Native 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18812762/
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-08-12 11:16:50  来源:igfitidea点击:

The APR based Apache Tomcat Native library was not found on the java.library.path

javaeclipsetomcatservlets

提问by nazar_art

I'm newly at server development and have been started from easy tutorial by Lars Vogel. Servlet and JSP development with Eclipse WTP .

我刚开始从事服务器开发,并且是从 Lars Vogel 的简单教程开始的。 使用 Eclipse WTP 进行 Servlet 和 JSP 开发

Step by stepaccord this tutorial:

一步一步地按照本教程:

  • installed Eclipse Java EE Kepler;
  • installed tomcat 7 on Ubuntu 12.04 - http://localhost:8080/shows correct tomcat page;
  • Setting up tomcat runtime environments into eclipse;
  • added tomcat server to eclipse;
  • create DAO;
  • created the Servlet;
  • run =>
  • 安装了 Eclipse Java EE Kepler;
  • 在 Ubuntu 12.04 上安装了 tomcat 7 -http://localhost:8080/显示正确的 tomcat 页面;
  • 在eclipse中设置tomcat运行环境;
  • 将 tomcat 服务器添加到 eclipse;
  • 创造DAO
  • 创建了 Servlet;
  • 运行 =>

And here I caught next prompt:

在这里我抓住了下一个提示:

Sep 15, 2013 3:40:39 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Sep 15, 2013 3:40:42 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:com.filecounter' did not find a matching property.
Sep 15, 2013 3:40:43 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Sep 15, 2013 3:40:43 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 15, 2013 3:40:43 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 5203 ms
Sep 15, 2013 3:40:43 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 15, 2013 3:40:43 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
Sep 15, 2013 3:40:45 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [171] milliseconds.
Sep 15, 2013 3:40:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Sep 15, 2013 3:40:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 15, 2013 3:40:46 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2882 ms

Here is content of tomcat/libfolder:

这是tomcat/lib文件夹的内容:

nazar_art@nazar-desctop:/usr/local/tomcat/apache-tomcat-7.0.42/lib$ ls -lg
total 6132
-rwxrwxrwx 1 nazar_art   15264 Jul  2 10:59 annotations-api.jar
-rwxrwxrwx 1 nazar_art   54142 Jul  2 10:59 catalina-ant.jar
-rwxrwxrwx 1 nazar_art  134215 Jul  2 10:59 catalina-ha.jar
-rwxrwxrwx 1 nazar_art 1581311 Jul  2 10:59 catalina.jar
-rwxrwxrwx 1 nazar_art  257520 Jul  2 10:59 catalina-tribes.jar
-rwxrwxrwx 1 nazar_art 1801636 Jul  2 10:59 ecj-4.2.2.jar
-rwxrwxrwx 1 nazar_art   46085 Jul  2 10:59 el-api.jar
-rwxrwxrwx 1 nazar_art  123241 Jul  2 10:59 jasper-el.jar
-rwxrwxrwx 1 nazar_art  599428 Jul  2 10:59 jasper.jar
-rwxrwxrwx 1 nazar_art   88690 Jul  2 10:59 jsp-api.jar
-rwxrwxrwx 1 nazar_art  177598 Jul  2 10:59 servlet-api.jar
-rwxrwxrwx 1 nazar_art    6873 Jul  2 10:59 tomcat-api.jar
-rwxrwxrwx 1 nazar_art  796527 Jul  2 10:59 tomcat-coyote.jar
-rwxrwxrwx 1 nazar_art  235411 Jul  2 10:59 tomcat-dbcp.jar
-rwxrwxrwx 1 nazar_art   77364 Jul  2 10:59 tomcat-i18n-es.jar
-rwxrwxrwx 1 nazar_art   48693 Jul  2 10:59 tomcat-i18n-fr.jar
-rwxrwxrwx 1 nazar_art   51678 Jul  2 10:59 tomcat-i18n-ja.jar
-rwxrwxrwx 1 nazar_art  124006 Jul  2 10:59 tomcat-jdbc.jar
-rwxrwxrwx 1 nazar_art   23201 Jul  2 10:59 tomcat-util.jar

Here is content of catalina.2013-09-15.log.

这是 catalina.2013-09-15.log 的内容

Update:

更新:

Here is tutorial:
Installing Apache Tomcat Native on Linux Ubuntu 12.04

这是教程:
在 Linux Ubuntu 12.04 上安装 Apache Tomcat Native

Update2:

更新2:

Here is content of Data Access Object:

以下是数据访问对象的内容:

public class FileDao {

  public int getCount() {
    int count = 0;
    // Load the file with the counter
    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    PrintWriter writer = null ; 
    try {
      File f = new File("FileCounter.initial");
      if (!f.exists()) {
        f.createNewFile();
        writer = new PrintWriter(new FileWriter(f));
        writer.println(0);
      }
      if (writer !=null){
        writer.close();
      }

      fileReader = new FileReader(f);
      bufferedReader = new BufferedReader(fileReader);
      String initial = bufferedReader.readLine();
      count = Integer.parseInt(initial);
    } catch (Exception ex) {
      if (writer !=null){
        writer.close();
      }
    }
    if (bufferedReader != null) {
      try {
        bufferedReader.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return count;
  }

  public void save(int count) throws Exception {
    FileWriter fileWriter = null;
    PrintWriter printWriter = null;
    fileWriter = new FileWriter("FileCounter.initial");
    printWriter = new PrintWriter(fileWriter);
    printWriter.println(count);

    // Make sure to close the file
    if (printWriter != null) {
      printWriter.close();
    }
  }

} 

And here Servlet code:

这里是 Servlet 代码:

public class FileCounter extends HttpServlet {
  private static final long serialVersionUID = 1L;

  int count;
  private FileDao dao;

  public void init() throws ServletException {
    dao = new FileDao();
    try {
      count = dao.getCount();
    } catch (Exception e) {
      getServletContext().log("An exception occurred in FileCounter", e);
      throw new ServletException("An exception occurred in FileCounter"
          + e.getMessage());
    }
  }

  protected void doGet(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
    // Set a cookie for the user, so that the counter does not increate
    // every time the user press refresh
    HttpSession session = request.getSession(true);
    // Set the session valid for 5 secs
    session.setMaxInactiveInterval(5);
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    if (session.isNew()) {
      count++;
    }
    out.println("This site has been accessed " + count + " times.");
  }

  public void destroy() {
    super.destroy();
    try {
      dao.save(count);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

} 

I haven't had web.xmlyet.

我还没有web.xml

How to solve this trouble?

如何解决这个烦恼?

采纳答案by A4L

not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

在 java.library.path 上找不到:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

The native lib is expected in one of the following locations

本机库应位于以下位置之一

/usr/java/packages/lib/amd64
/usr/lib64
/lib64
/lib
/usr/lib

and not in

而不是在

tomcat/lib

The files in tomcat/libare all jarfile and are added by tomcat to the classpathso that they are available to your application.

中的文件tomcat/lib都是jar文件,并由 tomcat 添加到 中,classpath以便它们可用于您的应用程序。

The native lib is needed by tomcat to perform better on the platform it is installed on and thus cannot be a jar, for linux it could be a .sofile, for windows it could be a .dllfile.

tomcat 需要本机 lib 才能在它安装的平台上更好地执行,因此不能是jar,对于 linux 它可能是一个.so文件,对于 windows 它可能是一个.dll文件。

Just download the native library for your platformand place it in the one of the locations tomcat is expecting it to be.

只需为您的平台下载本机库并将其放置在 tomcat 期望的位置之一。

Note that you are not required to have this lib for development/test purposes. Tomcat runs just fine without it.

请注意,出于开发/测试目的,您不需要拥有此库。Tomcat 没有它也能正常运行。

org.apache.catalina.startup.Catalina start INFO: Server startup in 2882 ms

org.apache.catalina.startup.Catalina 启动信息:服务器启动时间为 2882 毫秒

EDIT

编辑

The output you are getting is very normal, it's just some logging outputs from tomcat, the line right above indicates that the server correctly started and is ready for operating.

你得到的输出很正常,只是tomcat的一些日志输出,上面的一行表示服务器正确启动并准备好运行。

If you are troubling with running your servlet then after the run on severcommand eclipse opens a browser window (embeded (default) or external, depends on your config). If nothing shows on the browser, then check the url bar of the browser to see whether your servlet was requested or not.

如果您在运行 servlet 时遇到麻烦,那么在run on sever命令 eclipse 之后打开一个浏览器窗口(嵌入(默认)或外部,取决于您的配置)。如果浏览器上没有任何显示,则检查浏览器的 url 栏以查看您的 servlet 是否被请求。

It should be something like that

应该是这样的

http://localhost:8080/<your-context-name>/<your-servlet-name>

EDIT 2

编辑 2

Try to call your servlet using the following url

尝试使用以下网址调用您的 servlet

http://localhost:8080/com.filecounter/FileCounter

Also each web project has a web.xml, you can find it in your project under WebContent\WEB-INF.

此外,每个 web 项目都有一个 web.xml,您可以在您的项目中找到它WebContent\WEB-INF

It is better to configure your servlets there using servlet-nameservlet-classand url-mapping. It could look like that:

最好使用servlet-nameservlet-class和配置您的 servlet url-mapping。它看起来像这样:

  <servlet>
    <description></description>
    <display-name>File counter - My first servlet</display-name>
    <servlet-name>file_counter</servlet-name>
    <servlet-class>com.filecounter.FileCounter</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>file_counter</servlet-name>
    <url-pattern>/FileFounter</url-pattern>
  </servlet-mapping>

In eclipse dynamic web project the default context name is the same as your project name.

在 Eclipse 动态 Web 项目中,默认上下文名称与您的项目名称相同。

http://localhost:8080/<your-context-name>/FileCounter

will work too.

也会工作。

回答by KCD

Regarding the original question asked in the title ...

关于标题中提出的原始问题......

  • sudo apt-get install libtcnative-1

  • or if you are on RHEL Linux yum install tomcat-native

  • sudo apt-get install libtcnative-1

  • 或者如果您使用的是 RHEL Linux yum install tomcat-native

The documentation states you need http://tomcat.apache.org/native-doc/

文档说明您需要http://tomcat.apache.org/native-doc/

  • sudo apt-get install libapr1.0-dev libssl-dev
  • or RHEL yum install apr-devel openssl-devel
  • sudo apt-get install libapr1.0-dev libssl-dev
  • 或 RHEL yum install apr-devel openssl-devel