[英]The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
[英]The APR based Apache Tomcat Native library was not found on the java.library.path
我剛從服務器開發,並從Lars Vogel的簡易教程開始。 使用Eclipse WTP進行Servlet和JSP開發 。
按照本教程一步一步 :
http://localhost:8080/
顯示正確的tomcat頁面; DAO
; 在這里我抓住了下一個提示:
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
UPDATE2:
以下是數據訪問對象的內容:
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
原生lib預計位於以下位置之一
/usr/java/packages/lib/amd64
/usr/lib64
/lib64
/lib
/usr/lib
而不是
tomcat/lib
tomcat/lib
中的文件都是jar
文件,並由tomcat添加到classpath
以便它們可供您的應用程序使用。
tomcat需要本機lib才能在安裝的平台上運行得更好,因此不能成為jar
,對於linux,它可能是.so
文件,對於windows,它可能是.dll
文件。
只需為您的平台下載本機庫 ,並將其放在tomcat期望的位置之一。
請注意,您不需要將此lib用於開發/測試目的。 沒有它,Tomcat運行得很好。
org.apache.catalina.startup.Catalina啟動INFO:服務器啟動時間為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-class
和url-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
也會工作。
關於標題中提出的原始問題......
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
yum install apr-devel openssl-devel
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.