日期:2014-05-16  浏览次数:20881 次

Tomcat启动时提示org.apache.catalina.core.AprLifecycleListener...
*网上针对此问题提供的文章很多,但多数和我遇到的情况有出入,所以我将其记录于此*

最近开发中需要使用Tomcat,随意找来个较新的版本6.0.20就用。发现启动时提示:
“2010-5-12 18:06:06 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: ...”,打印出的路径包括了%JAVA_HOME%/bin,%SystemRoot%/system32(WindowsXP),以及系统变量path的值。

在http://tomcat.apache.org/tomcat-6.0-doc/apr.html中,可以看到对APR的介绍:

    Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies. The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as sendfile, epoll and OpenSSL), OS level functionality (random number generation, system status, etc), and native process handling (shared memory, NT pipes and Unix sockets).

    These features allows making Tomcat a general purpose webserver, will enable much better integration with other native web technologies, and overall make Java much more viable as a full fledged webserver platform rather than simply a backend focused technology.

而且其安装需要以下组件的支持:
    * APR library
    * JNI wrappers for APR used by Tomcat (libtcnative)
    * OpenSSL libraries
在网上搜索到的结果中,给出如下的方案:
“到http://tomcat.heanet.ie/native/站点下载符合本地环境的tcnative-1.dll,然后拷贝到%SystemRoot%/system32下,重启Tomcat即可”,
这么简单?好吧。我来到http://tomcat.heanet.ie/native/发现最新的版本为1.1.14,而README提示稳定版本为1.1.12。下载完毕,拷贝到system32下,重启Tomcat,报错:

2010-5-12 17:55:42 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.12.
2010-5-12 17:55:42 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2010-5-12 17:55:43 org.apache.coyote.http11.Http11AprProtocol init
严重: Error initializing endpoint
org.apache.tomcat.jni.Error: ??????????ó??Э?鲻????????? 
at org.apache.tomcat.jni.Socket.create(Native Method)
at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:612)
at org.apache.coyote.http11.Http11AprProtocol.init(Http11AprProtocol.java:107)
at org.apache.catalina.connector.Connector.initialize(Connector.java:1058)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:677)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:795)
at org.apache.catalina.startup.Catalina.load(Catalina.java:535)
at org.apache.catalina.startup.Catalina.load(Catalina.java:555)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
。。。

首先声明的是,这个APR到底能给我带来什么样的实惠,我不清楚;但可以确定的是其安装所需的条件我是满足的,所以那就是拷贝的路径不正确。可是,换到%JAVA_HOME%/bin下仍然报同样的错误,那应该拷到哪里呢?我的同事建议我拷到%CATALINA_HOME%/bin下,这倒提醒了我。拷贝,重启,仍然报错。。。

看来应该是tcnative-1.dll版本的问题了。到apache tomcat站点重新下载了两个最新的版本:5.5.29,6.0.26,解压一看,问题明白了:tcnative-1.dll的最新版本为1.1.20,位置在/bin目录下,我将其拷贝到tomcat6.0.20的/bin下,重启,正常:
“2010-5-12 18:47:45 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.20.
2010-5-12 18:47:45 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].