在java.library.path上找不到基于APR的Apache Tomcat本机库
我刚开始从事服务器开发,从easy tutorial开始 拉尔斯·沃格尔。 逐步遵循本教程:在java.library.path上找不到基于APR的Apache Tomcat本机库,java,eclipse,tomcat,servlets,Java,Eclipse,Tomcat,Servlets,我刚开始从事服务器开发,从easy tutorial开始 拉尔斯·沃格尔。 逐步遵循本教程: 安装Eclipse Java EE开普勒 在Ubuntu 12.04上安装了tomcat 7-http://localhost:8080/显示正确的tomcat页面 在eclipse中设置tomcat运行时环境 在eclipse中添加tomcat服务器 创建DAO 创建Servlet 运行=> 在这里我看到了下一个提示: Sep 15, 2013 3:40:39 PM org.apache.cat
- 安装Eclipse Java EE开普勒李>
- 在Ubuntu 12.04上安装了tomcat 7-
显示正确的tomcat页面李>http://localhost:8080/
- 在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
更新:
以下是教程:更新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
如何解决这个问题?
在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,它可以是。因此文件,对于windows,它可以是.dll
文件
只需将其放置在tomcat期望的位置之一
请注意,出于开发/测试目的,不需要使用此库。没有它,Tomcat跑得很好
org.apache.catalina.startup.catalina启动信息:服务器启动时间为2882毫秒
编辑
您得到的输出非常正常,只是tomcat的一些日志输出,上面的行表示服务器已正确启动并准备好运行
如果您在运行servlet时遇到麻烦,那么在服务器上运行命令之后,eclipse会打开一个浏览器窗口(嵌入(默认)或外部,取决于您的配置)。如果浏览器上没有显示任何内容,则检查浏览器的url栏以查看是否请求了servlet
应该是这样的
http://localhost:8080/<your-context-name>/<your-servlet-name>
此外,每个web项目都有一个web.xml,您可以在项目的WebContent\web-INF
下找到它
最好使用servlet名称servlet类和url映射在那里配置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>
文件计数器-我的第一个servlet
文件计数器
com.filecounter.filecounter
文件计数器
/文件中心
在eclipse动态web项目中,默认上下文名称与项目名称相同
http://localhost:8080/<your-context-name>/FileCounter
http://localhost:8080//FileCounter
也可以。关于标题中的原始问题
sudo apt get install libtcnative-1
- 或者如果您使用的是RHEL Linux
yum安装tomcat native
文档说明您需要
sudo apt get安装libapr1.0-dev libssl dev
- 或RHEL
yum安装apr-devel-openssl-devel
在我的位置存在最后三条路径。我误解了如何准确下载这个libs?这里是tomcat 7-@nazar\u艺术的链接,请按照@nazar\u艺术中的说明操作,哪一个错误?如果在java.library.path上找不到允许在生产环境中实现最佳性能的基于APR的Apache Tomcat本机库
,请按照您找到的教程或Apache Tomcat站点链接中的步骤进行操作。或者你还有别的错误吗?(唯一的“错误”-实际上只是一个警告-我知道是关于ARP的!)我遵循了本教程,但可能错过了smt,因为该警告再次显示。我无法理解本教程的结尾现在我已经在/usr/local/apr/libtcnative-1.so.0.1.27中编译了Tomcat本机库,并且符号链接文件/usr/local/apr//libtcnative-1.so指向了库5。使用以下行创建或编辑$CATALINA_HOME/bin/setenv.sh文件:export LD_LIBRARY_PATH='$LD_LIBRARY_PATH:/usr/local/apr/lib'
@nazar\u art,请查看我的编辑!如果您刚开始使用servlet和tomcat,也可以忽略关于ARP的警告。@A4L我尝试了这个路径http://localhost:8080/com.filecounter/FileCounter
但它会抛出HTTP Status 404-/com.filecounter/filecounter
http://localhost:8080/<your-context-name>/FileCounter