gpt4 book ai didi

java - 为什么 Tomcat 会为现有的 JAR 文件抛出 FileNotFoundExceptions?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:28:49 25 4
gpt4 key购买 nike

我想知道什么会导致 Tomcat 或 native Java ZipFile.open声称文件不存在但实际上不存在的方法?这个在过去的一个月里,这一直是我的一些工作的障碍。它是尝试运行 tomcat7-maven-plugin 时发生。它工作正常在大多数机器上,包括我的 (OSX),但在我们的构建服务器上失败(LINUX)和我的一个同事的盒子(OSX,与我的笔记本电脑型号相同)。这是在 Maven 构建中看到的错误:

[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)

对于拉入的项目中的每个 JAR 文件,都会重复此错误来自 Maven 依赖项。有数百个。

请注意,我在其中一个的 ZipFile.open 调用处放置了一个断点出现故障的机器并在单独的终端中执行以下操作:

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

我可以确认所有“丢失”的 JAR 文件都立即存在在调用 native open 方法并抛出异常之前声称文件不存在。这让我怀疑JAR 文件可能已损坏,因此我从中复制了一个失败的 JAR 文件我同事的机器,并与我的本地副本进行了比较在成功构建和执行之后。它们是相同的,所以它看来“损坏的 JAR”理论已经过时了。

我也试过以下(没有成功):

  • 缩短使用的路径(我在某处读到可能有一个 256字符限制)。
  • 将 JAR 文件移动到不同的目录并更改 Tomcat配置指向新位置(它们在资源和我将它们移到了项目 base.dir)。
  • 设置从 Xmx256 到 Xmx4096 的各种 JVM 堆大小(我读了一些内存问题可能导致 Tomcat 声称文件丢失的帖子)。
  • 删除我们通常用于 web 应用程序的 permgen 设置。
  • 将“jarScanAllDirectories”选项设置为 false 或 truetomcat7-maven-plugin。
  • 下载 tomcat-maven-plugin 的源代码(包括来自 Apache SVN 的 tomcat7-maven-plugin),将它们与远程连接调试器到 Maven 并逐步执行(一切似乎直到 native ZipFile.open 调用之前都是相同的)。
  • 在构建过程中为 Maven 使用各种 Jenkins 作业设置服务器(可能无关紧要,因为这在同事的机器上也失败了没有 Jenkins 参与)。
  • 将我们的网络应用程序使用的所有环境变量与那些环境变量进行比较由我的同事使用(它们是相同的)。
  • 比较 JDK 版本(我们整个组织都标准化为 1.7.0_45)。
  • 比较 Tomcat 版本(我们有明确的 pom.xml 文件依赖7.0.53 版的 tomcat7-maven-plugin)。
  • 等待并希望问题自行解决。
  • 请我所有的同事看一看(这导致我尝试了一些以上,但问题还是没有解决)。

我已经无计可施了。我已经过了午夜好几天了只是想让这个东西工作。还剩下什么要看?

更新(2015 年 2 月 10 日):有人认为这是由于运行它的 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-plugin 之前运行。权限应该已经到位并且 JAR 文件应该是可提取的。我仍然不明白为什么这不起作用。

最佳答案

事实证明这根本不是权限问题。出于某种原因,将 JAR 文件从目录中复制出来并返回到目录中会导致它们被拾取(我在某处的建议中读到过)。阅读 cp 的“man”条目我发现它不保留“访问控制列表 (ACL) 和扩展属性 (EA),包括资源分支”,除非设置了 -p 标志(使用 mv 时默认情况下启用) ).我的猜测是删除此“访问控制”信息以某种方式使 tomcat7-maven-plugin 可以访问这些文件。我真的不知道问题的根本原因,这似乎有点粗略,但我很高兴它现在已得到修复。

如果有人可以明确地解释为什么这行得通,那么我会接受这个答案而不是这个答案。

关于java - 为什么 Tomcat 会为现有的 JAR 文件抛出 FileNotFoundExceptions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28361627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com