1

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

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

jeremysprofile
  • 10,028
  • 4
  • 33
  • 53

2 Answers2

3

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

<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>apache-jsp</artifactId>
  <version>9.4.31.v20200723</version>
  <classifier>nolog</classifier>
</dependency>
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Thanks, I will look into deduplicating my classes. Does the `nolog` classifier just prevent logs from being generated (meaning `juli` wouldn't be used at all)? – jeremysprofile Sep 15 '20 at 21:58
  • I was able to remove a bunch of duplicate classes, but it doesn't look like any related to juli. I updated my question with all of the duplicates still remaining. Do you have any other ideas I could try? – jeremysprofile Sep 15 '20 at 23:47
1

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.

Vanchev
  • 1,554
  • 1
  • 9
  • 7