WebappClassLoader 和 StandardJarScanner 有什么区别?

What's the difference between WebappClassLoader and StandardJarScanner?

我正在使用 tomcat7-maven-plugin to launch a web application from Maven during the pre-integration-test lifecycle phase,这样我就可以在集成测试阶段 运行 在本地对其进行测试。

我没有在 Web 应用程序本身上做太多工作,但为了记录它使用 JSP 和 Java 控制器,它们使用 Spring MVC 3.0 绑定在一起。

当我在自己的机器上 运行 Maven (mvn clean verify) 时,我看到插件的以下输出:

[INFO] --- tomcat7-maven-plugin:2.2:run-war-only (start-tomcat) @ MyProject ---
[INFO] Running war on http://localhost:8080/contentmain
[INFO] Using existing Tomcat server configuration at /Users/alexjohnson/MyWorkspace/MyProject/src/test/resources/com/MyCompany/MyProject/ui/automation/tomcat7
Jan 27, 2015 2:18:54 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: /Users/alexjohnson/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Jan 27, 2015 2:18:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 27, 2015 2:18:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jan 27, 2015 2:18:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8443"]
Jan 27, 2015 2:18:54 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 425 ms
Jan 27, 2015 2:18:54 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 27, 2015 2:18:54 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.53
Jan 27, 2015 2:18:55 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
// More startup stuff

这是按预期工作的。请注意 WebappClassLoader.validateJarFile 被调用。另请注意,APR 信息消息是预期的,因为我们没有在测试环境中使用这些库。

当我在构建服务器上 运行 Maven (mvn clean verify) 时,我看到插件的以下输出:

[INFO] --- tomcat7-maven-plugin:2.2:run-war-only (start-tomcat) @ MyProject ---
[INFO] Running war on http://localhost:8080/contentmain
[INFO] Using existing Tomcat server configuration at /opt/jenkins/workspace/BuildServerWorkspace/src/test/resources/com/MyCompany/MyProject/ui/automation/tomcat7
Jan 27, 2015 2:30:09 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
Jan 27, 2015 2:30:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 27, 2015 2:30:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jan 27, 2015 2:30:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8443"]
Jan 27, 2015 2:30:09 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 823 ms
Jan 27, 2015 2:30:09 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 27, 2015 2:30:09 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.53
Jan 27, 2015 2:30:10 PM org.apache.tomcat.util.scan.StandardJarScanner scan
WARNING: Failed to scan JAR [file:/opt/jenkins/BuildServerWorkspace/src/test/resources/com/MyCompany/MyProject/ui/automation/tomcat7/webapps/../../../../../../../../../../../target/MyProject/WEB-INF/lib/openws-1.5.1.jar] from WEB-INF/lib
java.io.FileNotFoundException: /opt/jenkins/BuildServerWorkspace/src/test/resources/com/MyCompany/MyProject/ui/automation/tomcat7/webapps/../../../../../../../../../../../target/MyProject/WEB-INF/lib/openws-1.5.1.jar (No such file or directory)
// Hundreds more FileNotFoundExceptions for JAR files.

有效。请注意,这次 StandardJarScanner.scan 被调用。另请注意,丢失的 JAR 文件似乎是在我的本地计算机上构建期间以相同的相对路径创建的(11 个目录来自 webapps,另外 5 个目录位于目标目录中)。我相信所有这些 JAR 文件都是针对第三方 Maven 依赖项的。

我已经阅读了官方 Java 文档,但找不到对 WebappClassLoader or the StandardJarScanner 的有用描述。我真正能收集到的是,它们都用于在 Tomcat 启动时从 JAR 文件加载 类。

我想知道的:

看看这个问题https://issues.apache.org/jira/browse/MTOMCAT-239 听起来像是来自 jenkins 的一些奇怪的路径,我不明白为什么..

WebAppClassLoader 和 StandardJarScanner 是苹果和橘子。 StandardJarScanner 始终在 WebAppClassLoader 之前运行,但仅在出现问题时才生成日志语句。这意味着 StandardJarScanner 日志语句与 WebAppClassLoader 日志语句出现在失败构建中的同一点。

由于我误读了这些日志语句,所以我最终问错了问题。我原来的问题仍然存在。我在 .

打开了一个新问题