java.util.ServiceConfigurationError:org.apache.juli.logging.Log:org.eclipse.jetty.apache.jsp.JuliLog不是子类型

问题描述

我正在尝试将十年前编写的项目移植到Java 11。

经过几天的努力,我陷入了这个错误

Caused by: 
java.util.ServiceConfigurationError: org.apache.juli.logging.Log: org.eclipse.jetty.apache.jsp.JuliLog not a subtype
    at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:588)
    at java.base/java.util.ServiceLoader$LazyClasspathLookupIterator.hasNextService(ServiceLoader.java:1236)
...

如果我通过其jar -xf和uberjar {rip} grep,我会同时看到JuliLogjuli.logging版本:

rg  "JuliLog|juli\.logging"
jar/meta-inf/services/org.apache.juli.logging.Log
1:org.eclipse.jetty.apache.jsp.JuliLog

jar/meta-inf/maven/org.mortbay.jasper/apache-jsp/pom.xml
216:              filter:="(osgi.serviceloader=org.apache.juli.logging.Log)";resolution:=optional;cardinality:=multiple,235:                  org.apache.juli.logging;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}",jar/meta-inf/maven/org.eclipse.jetty/apache-jsp/pom.xml
28:            <Provide-Capability>osgi.serviceloader;osgi.serviceloader=javax.servlet.ServletContainerInitializer,osgi.serviceloader;osgi.serviceloader=org.apache.juli.logging.Log</Provide-Capability>
45:                <exclude>meta-inf/services/org.apache.juli.logging.Log</exclude>

由此,对于同一groupId工件,我看到了不同的apache-jsp,但是事实证明一个是另一个的依赖项。

mvn dependency:tree  | grep -i apache-jsp -C5
...
[INFO] +- org.eclipse.jetty:jetty-servlet:jar:9.4.31.v20200723:compile
[INFO] |  \- org.eclipse.jetty:jetty-security:jar:9.4.31.v20200723:compile
[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.4.31.v20200723:compile
[INFO] +- org.eclipse.jetty:jetty-xml:jar:9.4.31.v20200723:compile
[INFO] |  \- org.eclipse.jetty:jetty-util:jar:9.4.31.v20200723:compile
[INFO] +- org.eclipse.jetty:apache-jsp:jar:9.4.31.v20200723:compile
[INFO] |  +- org.eclipse.jetty.toolchain:jetty-schemas:jar:3.1.2:compile
[INFO] |  +- org.mortbay.jasper:apache-jsp:jar:8.5.54:compile
[INFO] |  |  +- org.mortbay.jasper:apache-el:jar:8.5.54:compile
...

在pom中,我仅指定月食apache-jsp,这是为了防止与缺乏JSP支持2020-09-15 10:08:50.037:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /my-application,did not find org.eclipse.jetty.jsp.JettyJspServlet)有关的错误

StackOverflow上的其他问题与对tomcat(either explicitlyvia Spring)或gwt的依赖关系有关。我什么都没有,但是如果重要的话,我确实对其他码头缸有依赖性:

mvn dependency:tree  | grep -i tomcat -C5
# no results
mvn dependency:tree  | grep -i gwt -C5
# no results
mvn dependency:tree  | grep -i jetty -C5
...
[INFO] +- org.eclipse.jetty:jetty-server:jar:9.4.31.v20200723:compile
[INFO] |  +- org.eclipse.jetty:jetty-http:jar:9.4.31.v20200723:compile
[INFO] |  \- org.eclipse.jetty:jetty-io:jar:9.4.31.v20200723:compile
[INFO] +- org.eclipse.jetty:jetty-servlet:jar:9.4.31.v20200723:compile
[INFO] |  \- org.eclipse.jetty:jetty-security:jar:9.4.31.v20200723:compile
[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.4.31.v20200723:compile
[INFO] +- org.eclipse.jetty:jetty-xml:jar:9.4.31.v20200723:compile
[INFO] |  \- org.eclipse.jetty:jetty-util:jar:9.4.31.v20200723:compile
[INFO] +- org.eclipse.jetty:apache-jsp:jar:9.4.31.v20200723:compile
[INFO] |  +- org.eclipse.jetty.toolchain:jetty-schemas:jar:3.1.2:compile
[INFO] |  +- org.mortbay.jasper:apache-jsp:jar:8.5.54:compile
[INFO] |  |  +- org.mortbay.jasper:apache-el:jar:8.5.54:compile
[INFO] |  |  \- org.eclipse.jdt:ecj:jar:3.19.0:compile
[INFO] |  \- org.eclipse.jetty:jetty-annotations:jar:9.4.31.v20200723:compile
[INFO] |     +- org.eclipse.jetty:jetty-plus:jar:9.4.31.v20200723:compile
[INFO] |     |  \- org.eclipse.jetty:jetty-jndi:jar:9.4.31.v20200723:compile
...

其他解决方案被明确排除在项目中apache-jsp之外,但这正是提供我的JSP支持的原因,因此对我来说不起作用。

我以为我可以使用<exclusion>,但是mvn dependency:tree | grep -i juli -C5不会返回任何结果,所以我不确定如何在此处添加一个


更新:多亏了Joakim,我能够<exclusion>整理一堆重复的类,从而大大清理了我的罐子,以至于我唯一的重复是about.html文件以及jmockit和junit之间的一些重叠:

mvn org.basepom.maven:duplicate-finder-maven-plugin:check

...
[INFO] Checking compile classpath
[INFO] Checking runtime classpath
[INFO] Checking test classpath
[WARNING] Found duplicate and different resources in [org.eclipse.jdt:ecj:3.19.0,org.eclipse.jetty.toolchain:jetty-schemas:3.1.2,org.eclipse.jetty:apache-jsp:9.4.31.v20200723,org.eclipse.jetty:jetty-annotations:9.4.31.v20200723,org.eclipse.jetty:jetty-http:9.4.31.v20200723,org.eclipse.jetty:jetty-io:9.4.31.v20200723,org.eclipse.jetty:jetty-jndi:9.4.31.v20200723,org.eclipse.jetty:jetty-plus:9.4.31.v20200723,org.eclipse.jetty:jetty-security:9.4.31.v20200723,org.eclipse.jetty:jetty-server:9.4.31.v20200723,org.eclipse.jetty:jetty-servlet:9.4.31.v20200723,org.eclipse.jetty:jetty-util:9.4.31.v20200723,org.eclipse.jetty:jetty-webapp:9.4.31.v20200723,org.eclipse.jetty:jetty-xml:9.4.31.v20200723,org.eclipse.jgit:org.eclipse.jgit:1.0.0.201106090707-r]:
[WARNING]   about.html
[WARNING] Found duplicate and different resources in [org.eclipse.jdt:ecj:3.19.0,org.eclipse.jgit:org.eclipse.jgit:1.0.0.201106090707-r]:
[WARNING]   about.html
[WARNING] Found duplicate and different classes in [com.googlecode.jmockit:jmockit:1.7,junit:junit:4.11]:
[WARNING]   junit.framework.TestResult
[WARNING]   org.junit.runner.Runner
[WARNING] Found duplicate and different resources in [org.eclipse.jdt:ecj:3.19.0,org.eclipse.jgit:org.eclipse.jgit:1.0.0.201106090707-r]:
[WARNING]   about.html
...

不幸的是,这不能解决我的问题。

解决方法

您在类路径中和/或在多个ClassLoader位置中有多个org.apache.juli.logging.Log的副本的可能性很高,这令人感到困惑。

重要提示:您确实应该解决重复的类问题。

由于您正在使用Maven,请使用重复的类查找器插件之一。

请参阅:Find duplicated classes in classpath

选项B,一旦您解决了所有重复的类问题,将对nolog使用apache-jsp分类的工件。

https://search.maven.org/artifact/org.eclipse.jetty/apache-jsp/9.4.31.v20200723/jar

<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>apache-jsp</artifactId>
  <version>9.4.31.v20200723</version>
  <classifier>nolog</classifier>
</dependency>