2015-02-06 43 views
4

我想知道什麼可能會導致Tomcat或本地Java ZipFile.open 方法聲稱一個文件實際上不存在時?這個 對我過去一個月來的一些工作來說是一個阻礙問題。在嘗試運行tomcat7-maven-plugin時發生了 。在大多數機器(包括我的OSX)上它工作正常,但在我們的構建服務器 (LINUX)和我的同事盒子之一(OSX,與我的同型號筆記本電腦)上失敗。 這裏的錯誤所看到的Maven構建:對於參加了在 從Maven依賴拉項目中的每個JAR文件上重複爲什麼Tomcat爲現有的JAR文件拋出FileNotFoundExceptions?

[INFO] --- tomcat7-maven-plugin:2.2:run (start-tomcat) @ PROJECT --- 
[INFO] Running war on http://localhost:8080/contentmain 
[INFO] Using existing Tomcat server configuration at 
/WORKSPACE/PROJECT/tomcat7 
Feb 05, 2015 11:17:53 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 
Feb 05, 2015 11:17:54 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8080"] 
Feb 05, 2015 11:17:54 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
Feb 05, 2015 11:17:54 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8443"] 
Feb 05, 2015 11:17:54 PM org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 651 ms 
Feb 05, 2015 11:17:54 PM org.apache.catalina.core.StandardService 
startInternal 
INFO: Starting service Catalina 
Feb 05, 2015 11:17:54 PM org.apache.catalina.core.StandardEngine 
startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.53 
Feb 05, 2015 11:17:54 PM org.apache.tomcat.util.scan.StandardJarScanner 
scan 
WARNING: Failed to scan JAR 
[file:/WORKSPACE/tomcat7/webapps/../../target/PROJECT/WEB-INF/lib/openws-1. 
5.1.jar] from WEB-INF/lib 
java.io.FileNotFoundException: 
/WORKSPACE/PROJECT/tomcat7/webapps/../../target/PROJECT/WEB-INF/lib/openws- 
1.5.1.jar (No such file or directory) 
    at java.util.zip.ZipFile.open(Native Method) 
    at java.util.zip.ZipFile.<init>(ZipFile.java:215) 
    at java.util.zip.ZipFile.<init>(ZipFile.java:145) 
    at java.util.jar.JarFile.<init>(JarFile.java:154) 
    at java.util.jar.JarFile.<init>(JarFile.java:91) 
    at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93) 
    at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69) 
    at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:99) 
    at 
sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122 
) 
    at 
sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java: 
89) 
    at org.apache.tomcat.util.scan.FileUrlJar.<init>(FileUrlJar.java:41) 
    at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:34) 
    at 
org.apache.catalina.startup.ContextConfig$FragmentJarScannerCallback.scan(C 
ontextConfig.java:2612) 
    at 
org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.j 
ava:259) 
    at 
org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java 
:178) 
    at 
org.apache.catalina.startup.ContextConfig.processJarsForWebFragments(Contex 
tConfig.java:1868) 
    at 
org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1256 
) 
    at 
org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java 
:873) 
    at 
org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java 
:371) 
    at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSuppo 
rt.java:117) 
    at 
org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.jav 
a:90) 
    at 
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java 
:5355) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at 
org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1 
559) 
    at 
org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1 
549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1 
145) 
    at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java: 
615) 
    at java.lang.Thread.run(Thread.java:745) 

此錯誤。有數百個這樣的。

請注意,我已經放在一個斷點在ZipFile.open呼叫的 失敗的機器之一,並執行在一個單獨的終端如下:

cd /WORKSPACE/PROJECT/tomcat7/webapps/../../target/PROJECT/WEB-INF/lib/ 
ls -la 

我可以證實,所有的「失蹤」的JAR文件在那裏立即 之前調用本地open方法和異常拋出 聲稱文件不存在。這使我懷疑 JAR文件可能損壞,所以我複製從 我的同事的機器出現故障的JAR文件中的一個,並與一個本地副本我在成功地構建和執行有 執行的差異。它們是相同的,所以它看起來「腐敗的JAR」理論已經出來。

我也試過以下(沒有成功):

  • 縮短使用的路徑(我讀的地方,可能有256 字符的限制)。
  • 將JAR文件移動到不同的目錄並將Tomcat 配置更改爲指向新的位置(它們在資源下,而我將它們移動到項目base.dir中) 。
  • 設置從Xmx256各種JVM堆大小Xmx4096(我在幾個 帖子讀取內存問題可能會導致Tomcat的宣稱文件丟失)。
  • 刪除我們通常用於web應用程序的permgen設置。
  • 將「jarScanAllDirectories」選項設置爲false或true對於 tomcat7-maven-plugin。
  • 下載從Apache的SVN爲Tomcat-行家-插件來源(這包括 tomcat7-行家-插件),與遠程 調試器的Maven附接它們,並通過執行步進(一切似乎 相同的權利,直到本地ZipFile.open調用)。
  • 在構建 服務器(可能無關緊要,因爲這在沒有Jenkins參與的情況下,同事的機器 上也失敗),在各種Jenkins作業設置中使用Maven的各種Jenkins作業設置。
  • 所有使用我們的web應用程序由我的同事所使用的那些 環境變量的比較(它們是相同的)。
  • 比較JDK版本(我們的整個組織在1.7.0_45標準化)。
  • 比較的Tomcat版本(我們有 在7.0.53版本的tomcat7 - Maven的插件明確pom.xml文件依賴)。
  • 等待並希望問題能夠解決。
  • 要求所有我的同事去看看(這導致了一些嘗試的 以上,但問題仍然沒有得到解決)。

我在黔驢技窮就在這裏。我已經在午夜過了幾天 只是想讓這件事情起作用。還有什麼要看?

UPDATE(2/10/2015):有人建議,這是由於運行Jenkins機器時缺少文件許可權造成的。我沒有訪問到這是發生在服務器上,但我沒有得到一個腳本運行有:

echo Displaying JAR files with current permissions... 
ls -la ./target/MyProject/WEB-INF/lib/ 

echo Adding read, write, and execute permissions to JAR files... 
chmod -R 777 ./target/MyProject/WEB-INF/lib/ 

echo Displaying JAR files with updated permissions... 
ls -la ./target/MyProject/WEB-INF/lib/ 

這將產生輸出類似如下:

[INFO] --- exec-maven-plugin:1.3.2:exec (update_jar_file_permissions) @ 
MyProject --- 
Displaying JAR files with current permissions... 
total 124556 
drwxr-xr-x 2 jenkins users 20480 Feb 10 17:26 . 
drwxr-xr-x 6 jenkins users  4096 Feb 10 17:26 .. 
-rw-r--r-- 1 jenkins users 62983 Jan 22 00:11 activation-1.1.jar 
-rw-r--r-- 1 jenkins users 351656 Jan 22 00:25 amqp-client-3.1.3.jar 
-rw-r--r-- 1 jenkins users 74080 Jan 22 00:25 annotations-2.0.0.jar 
-rw-r--r-- 1 jenkins users 445288 Jan 22 00:25 antlr-2.7.7.jar 
-rw-r--r-- 1 jenkins users 895124 Jan 22 00:25 antlr-3.2.jar 

Adding read, write, and execute permissions to JAR files... 
Displaying JAR files with updated permissions... 
total 124556 
drwxrwxrwx 2 jenkins users 20480 Feb 10 17:26 . 
drwxr-xr-x 6 jenkins users  4096 Feb 10 17:26 .. 
-rwxrwxrwx 1 jenkins users 62983 Jan 22 00:11 activation-1.1.jar 
-rwxrwxrwx 1 jenkins users 351656 Jan 22 00:25 amqp-client-3.1.3.jar 
-rwxrwxrwx 1 jenkins users 74080 Jan 22 00:25 annotations-2.0.0.jar 
-rwxrwxrwx 1 jenkins users 445288 Jan 22 00:25 antlr-2.7.7.jar 
-rwxrwxrwx 1 jenkins users 895124 Jan 22 00:25 antlr-3.2.jar 

正如你所看到的, 缺少權限。然而,這並沒有 解決了這個問題:

Feb 10, 2015 5:27:54 PM org.apache.tomcat.util.scan.StandardJarScanner scan 
WARNING: Failed to scan JAR [file:/opt/jenkins/workspace/MY_JENKINS_JOB/tomcat7/webapps/../../target/MY_PROJECT/WEB-INF/lib/activation-1.1.jar] from WEB-INF/lib 
java.io.FileNotFoundException: /opt/jenkins/workspace/MY_JENKINS_JOB/tomcat7/webapps/../../target/MY_PROJECT/WEB-INF/lib/activation-1.1.jar (No such file or directory) 
at java.util.zip.ZipFile.open(Native Method) 

劇本是tomcat7 - Maven的插件之前正確運行。權限應該已經到位,並且JAR文件應該是可解析的。我仍然不明白爲什麼這不起作用。

+0

您的應用程序是否有權限閱讀JAR? – 2015-02-06 08:47:16

+0

是的,謝謝你的建議。請參閱上面我更新的問題。 – 2015-02-11 02:00:12

+2

在Linux上,核選項將在運行Tomcat的JVM進程上運行'strace'。這可以讓你看到進程正在使用什麼系統調用來訪問這些文件,以及到底發生了什麼。 – Kenster 2015-02-11 03:04:36

回答

1

事實證明,這根本不是一個權限問題。出於某種原因,將JAR文件複製出目錄並返回到目錄,導致它們被拾取(我在某個地方的某個建議中閱讀了這個內容)。閱讀cp的'man'條目,我發現它不保留「訪問控制列表(ACL)和擴展屬性(EA),包括資源分支」,除非設置了-p標誌(默認情況下,這在使用mv )。我的猜測是,刪除這個「訪問控制」信息以某種方式使這些文件可以被tomcat7-maven-plugin訪問。這似乎有點粗略,我並不真正瞭解問題的根源,但我很高興它現在已經修復。

如果有人能明確地解釋爲什麼這個工作,然後我會接受,作爲一個答案,而不是這一個。