【问题标题】:The APR based Apache Tomcat Native library was not found on the java.library.path在 java.library.path 上找不到基于 APR 的 Apache Tomcat 本机库
【发布时间】:2013-09-19 16:51:34
【问题描述】:

我是服务器开发的新手,从简单教程开始 拉斯沃格尔。 Servlet and JSP development with Eclipse WTP .

一步一步按照本教程:

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

在这里我捕捉到了下一个提示:

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

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

更新:

这里是教程:
Installing Apache Tomcat Native on Linux Ubuntu 12.04

更新2:

这是数据访问对象的内容:

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 代码:

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

如何解决这个问题?

【问题讨论】:

  • @A4L 我尝试了这条路径http://localhost:8080/com.filecounter/FileCounter,但它抛出了HTTP Status 404 - /com.filecounter/FileCounter

标签: java eclipse tomcat servlets


【解决方案1】:

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

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

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

而不是在

tomcat/lib

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

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

只需 download the native library for your platform 并将其放置在 tomcat 期望的位置之一。

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

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

编辑

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

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

应该是这样的

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

编辑 2

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

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

另外每个web项目都有一个web.xml,你可以在你的项目WebContent\WEB-INF下找到它。

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

  <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 项目中,默认上下文名称与您的项目名称相同。

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

也可以。

【讨论】:

  • 在我的位置存在最后三个路径。我误解了如何准确下载这个库?这是 tomcat 7 的链接 - tomcat.apache.org/tomcat-7.0-doc/apr.html
  • @nazar_art 按照page中的说明进行操作
  • @nazar_art 哪个错误?如果是The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path,请按照您找到的教程或 apache tomcat 站点的链接中的步骤进行操作。还是你有另一个错误? (唯一的“错误”——实际上只是一个警告——我看到的是关于 ARP!)
  • 我按照本教程进行操作,但可能错过了 smt,因为此警告再次显示。我无法理解本教程的结尾Now I have compiled Tomcat Native library in /usr/local/apr/libtcnative-1.so.0.1.27 and symbolic link file /usr/local/apr/@libtcnative-1.so pointed to the library 5. Create or edit the $CATALINA_HOME/bin/setenv.sh file with following lines : export LD_LIBRARY_PATH='$LD_LIBRARY_PATH:/usr/local/apr/lib'
  • @nazar_art,请看我的编辑!如果您刚刚使用 servlet 和 tomcat 启动,也请忽略有关 ARP 的警告。
【解决方案2】:

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

  • sudo apt-get install libtcnative-1

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

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

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

【讨论】:

    猜你喜欢
    • 2011-05-15
    • 2020-01-02
    • 2012-02-01
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    相关资源
    最近更新 更多