apache / jena

Apache Jena
https://jena.apache.org/
Apache License 2.0
1.09k stars 646 forks source link

fuseki.Fuseki: jetty.servlet.ServletContextHandler$Context does not implement the requested interface javax.servlet.ServletContext #2120

Closed AronBuzogany closed 8 months ago

AronBuzogany commented 9 months ago

Version

4.6.1

Question

When switching from:

<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.35.0</version>

to

<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.3.1</version>

in my pom.xml and rebuilding my project I get the following error:

java.lang.IncompatibleClassChangeError: Class org.eclipse.jetty.servlet.ServletContextHandler$Context does not implement the requested interface javax.servlet.ServletContext

in org.apache.jena.fuseki.Fuseki.setVerbose

I am using:

<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>

I tried different versions of javax.servlet, but none of them resolved the issue, nor did other Jena versions.

What does this error mean? How can I solve it?

rvesse commented 9 months ago

This looks like a dependency conflict between different versions of the Servlet API and Jetty

You will need to look at your full mvn dependency:tree output to see what versions are being referenced (both directly and indirectly). Remember that closest dependency wins in Maven if you have multiple paths to the same dependency.

Once you've figured out where the multiple sources of Servlet API and/or Jetty dependencies are coming from you'll need to adjust your dependencies and/or exclusions appropriately.

The fact this this occurred when upgrading the wiremock dependency suggests that the major version bump changes those transitive dependencies in some way. Bear in mind that Servlet 4 -> Servlet 5 was a breaking change with the package changing from javax.servlet to jakarta.servlet so if you have mixed versions of this in your dependency tree you'll run into errors like these.

afs commented 9 months ago

org.wiremock:wiremock version 3.3.1 depends on Jetty11 which uses jakarta.servlet.

Wiremock switched from Jetty 9 (package space javax.servlet) to Jetty 11 (jakarta.servlet) at 3.0.0.

The changelog below represents key changes between 2.35.0 and 3.0.0. ... 💥 Breaking changes ... Upgrade from Jetty 9 to Jetty 11 (Changelog)

Apache Jena Fuseki 4.6.1 uses Jetty 10 (javax.servlet).

Jena is switching to jakarta.servlet with Jena 5.0.0.

AronBuzogany commented 9 months ago

Thank you for the detailed explanation! Is there a way to make the 2 dependencies work with each other in this case? I tried looking at the dependency tree as suggested, but as the dependencies go under different names I do not know how to handle this.

afs commented 9 months ago

The way the javax.servlet => jakarta.servlet happens means they can't be mixed.

Anything else is modify and recompile one or other of the systems. In a non-production setting, you can try Jena 5 development (with all the consequences of running a development snapshot).

wiremock 3.0.0 was August this year.

Can you use wiremock 2 for now?

(And before you ask :smile: Jena5 is "sometime hopefully soon" - the project is all volunteer time.)

afs commented 8 months ago

Closing question.