java.util.ServiceConfigurationError: org.apache.juli.logging.Log: org.eclipse.jetty.apache.jsp.JuliLog not a subtype

huangapple go评论79阅读模式
英文:

java.util.ServiceConfigurationError: org.apache.juli.logging.Log: org.eclipse.jetty.apache.jsp.JuliLog not a subtype

问题

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

经过几天的努力和一些进展,我卡在了这个错误上:

Caused by:
java.util.ServiceConfigurationError: org.apache.juli.logging.Log: org.eclipse.jetty.apache.jsp.JuliLog不是子类型
	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:588)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1236)
...

如果我通过jar -xf解压我的超级JAR文件,然后使用(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>

从中,我看到了相同的apache-jsp构件的不同groupId,但事实证明其中一个是另一个的依赖:

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中,我只指定了Eclipse的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的依赖有关(明确地 或者 通过 Spring) 或者gwt有关。我没有遇到这些问题,但我确实在其他jetty的JAR文件上有一些依赖,如果有关的话:

mvn dependency:tree  | grep -i tomcat -C5
# 没有结果
mvn dependency:tree  | grep -i gwt -C5
# 没有结果
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从项目中排除,但这是提

英文:

I am trying to port over a project written over a decade ago to Java 11.

After a couple days and some progress, I'm stuck at this error:

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

If I jar -xf my uberjar and (rip)grep through it, I see both the JuliLog and juli.logging versions:

rg  &quot;JuliLog|juli\.logging&quot;
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:=&quot;(osgi.serviceloader=org.apache.juli.logging.Log)&quot;;resolution:=optional;cardinality:=multiple,
235:                  org.apache.juli.logging;version=&quot;${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}&quot;,

jar/META-INF/maven/org.eclipse.jetty/apache-jsp/pom.xml
28:            &lt;Provide-Capability&gt;osgi.serviceloader;osgi.serviceloader=javax.servlet.ServletContainerInitializer,osgi.serviceloader;osgi.serviceloader=org.apache.juli.logging.Log&lt;/Provide-Capability&gt;
45:                &lt;exclude&gt;META-INF/services/org.apache.juli.logging.Log&lt;/exclude&gt;

From that, I saw different groupIds for the same apache-jsp artifact, but it turns out one is a dependency of the other:

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
...

In my pom, I only specify the eclipse apache-jsp, which I'm including to prevent an error relating to lack of JSP support (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)

The other questions on StackOverflow were relating to dependencies on tomcat (either explicitly or via Spring) or gwt. I have none of those, but I do have some dependencies on other jetty jars, if that matters:

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
...

Other solutions were explicitly excluding apache-jsp from the project, but this is what is providing my JSP support, so that doesn't work for me.

I thought I could use an &lt;exclusion&gt;, but mvn dependency:tree | grep -i juli -C5 returns no results, so I'm not sure how I could add one here.


Update: Thanks to Joakim, I was able to significantly clean up my jar by &lt;exclusion&gt;ing a bunch of duplicate classes, to the point my only duplicates are about.html files and some overlap between jmockit and 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.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 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.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
...

Unfortunately, this did not solve my issue.

答案1

得分: 3

以下是您要翻译的内容:

有很大的可能性在您的类路径中和/或多个类加载器位置中有多个org.apache.juli.logging.Log的副本,这可能会导致混淆。

重要: 您真的应该解决重复的类问题。

由于您正在使用Maven,可以使用其中一个重复类查找插件。

参考:https://stackoverflow.com/questions/12536482/find-duplicated-classes-in-classpath

选项B,在您解决了所有重复类的问题之后,是使用apache-jspnolog分类工件。

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>
英文:

Odds are high that you have multiple copies of org.apache.juli.logging.Log in your classpath and/or in multiple ClassLoader locations and it's getting confused.

Important: You really should fix your duplicate classes issue.

Since you are using maven, use one of the duplicate class finder plugins.

See: https://stackoverflow.com/questions/12536482/find-duplicated-classes-in-classpath

Option B, once you have fixed all of your duplicate class issues, is to use the nolog classified artifact for apache-jsp.

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

&lt;dependency&gt;
  &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
  &lt;artifactId&gt;apache-jsp&lt;/artifactId&gt;
  &lt;version&gt;9.4.31.v20200723&lt;/version&gt;
  &lt;classifier&gt;nolog&lt;/classifier&gt;
&lt;/dependency&gt;

答案2

得分: 1

我遇到了相同的问题,但情况有点不同。使用了一个带有jetty的docker镜像,并且没有直接连接到apache-jsp或任何使用了org.apache.juli.logging.Log的内容,所以很奇怪为什么会发生这种情况。

经过进一步的调查,我注意到在创建的docker镜像的WEB-INF/lib文件夹下,我同时有apache-jsp...jar(两个不同版本)和gwt-dev.jar。我移除了这些jar包,问题得以解决。

这实际上是一个很旧的问题,所以我猜现在可能已经不再相关,但以防万一,我想写下这个笔记,或许你甚至没有直接依赖于apache-jsp,而构建系统(我这里是gradle)在某种情况下会自动获取它(可能是通过某个间接依赖)。

当然,仅仅从docker文件中移除jar包应该被视为一种危险的操作,因为这可能会在运行时引发其他问题,所以请谨慎操作。

英文:

I had the same issue, but it was a bit different setup. A docker image with jetty was used and there were no direct connections to apache-jsp or anything that used org.apache.juli.logging.Log, so it was a bit weird why it was happening.

Upon further investigation, I noticed that I had both apache-jsp...jar (2 different versions of it) and gwt-dev.jar in the created docker image, under the WEB-INF/lib folder. I removed those jars and the problem was resolved.

This is a really old problem, so I guess it is probably not even relevant to people anymore, but just in case, wanted to write down that maybe you don't even have a direct dependency to apache-jsp, and the build system (gradle in my case) somehow fetches it (maybe via a indirect dependency on something).

Of course just removing jars from the docker file should be considered a dangerous action, as one may encouter other issues on runtime, so do this with caution.

huangapple
  • 本文由 发表于 2020年9月16日 05:29:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63910110.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定