在 java.library.path 上找不到基于 APR 的 Apache Tomcat Native 库 [英] The APR based Apache Tomcat Native library was not found on the java.library.path

查看:54
本文介绍了在 java.library.path 上找不到基于 APR 的 Apache Tomcat Native 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始做服务器开发,从简单的教程开始拉斯·沃格尔.使用 Eclipse WTP 进行 Servlet 和 JSP 开发.

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

循序渐进符合本教程:

Step by step accord this tutorial:

  • 安装了 Eclipse Java EE Kepler;
  • 在 Ubuntu 12.04 上安装了 tomcat 7 - http://localhost:8080/ 显示正确的 tomcat 页面;
  • 在eclipse中设置tomcat运行环境;
  • 将tomcat服务器添加到eclipse中;
  • 创建DAO;
  • 创建了 Servlet;
  • 运行 =>
  • 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 =>

在这里我发现了下一个提示:

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

这是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

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

更新:

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

更新 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();
    }
  }

} 

这里是 Servlet 代码:

And here Servlet code:

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();
    }
  }

} 

我还没有 web.xml.

如何解决这个问题?

推荐答案

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

not found on the 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

而不是在

tomcat/lib

tomcat/lib中的文件都是jar文件,由tomcat添加到classpath中,这样你的应用就可以使用了.

The files in tomcat/lib are all jar file and are added by tomcat to the classpath so that they are available to your application.

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

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 .so file, for windows it could be a .dll file.

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

Just download the native library for your platform and 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.

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

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

编辑

你得到的输出很正常,只是tomcat的一些日志输出,上面一行表示服务器正确启动,可以运行了.

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.

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

If you are troubling with running your servlet then after the run on sever command 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.

应该是这样的

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

编辑 2

尝试使用以下 URL 调用您的 servlet

Try to call your servlet using the following url

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

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

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

最好使用 servlet-name servlet-classurl-mapping 在那里配置你的 servlet.它可能看起来像这样:

It is better to configure your servlets there using servlet-name servlet-class and url-mapping. It could look like that:

  <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>

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

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

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

也能用.

这篇关于在 java.library.path 上找不到基于 APR 的 Apache Tomcat Native 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆