Search code examples
jerseyjax-rsjettyembedded-jettyjersey-3.0

How to configure Jersey 3x to work with embedded Jetty 9x


I am trying to upgrade to Jersey 3x from 2.35 to work with Jetty 9x embedded so that I may use the Asynchronous Server API that is supported in 3x. The current maven pom.xml is:

<properties>
    <jersey.version>2.35</jersey.version>
    <!--jersey.version>3.0.0</jersey.version-->
    <jetty.version>9.4.28.v20200408</jetty.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<!--Test Dependencies-->
</dependencies>
   <dependency>
       <groupId>org.eclipse.jetty</groupId>
       <artifactId>jetty-server</artifactId>
       <version>${jetty.version}</version>
       <scope>test</scope>
   </dependency>
   <dependency>
       <groupId>org.eclipse.jetty</groupId>
       <artifactId>jetty-servlet</artifactId>
       <version>${jetty.version}</version>
       <scope>test</scope>
   </dependency>
   <dependency>
       <groupId>org.eclipse.jetty</groupId>
       <artifactId>jetty-servlets</artifactId>
       <version>${jetty.version}</version>
       <scope>test</scope>
   </dependency>
   <dependency>
       <groupId>org.glassfish.jersey.core</groupId>
       <artifactId>jersey-server</artifactId>
       <version>${jersey.version}</version>
       <scope>test</scope>
   </dependency>
   <dependency>
       <groupId>org.glassfish.jersey.containers</groupId>
       <artifactId>jersey-container-servlet-core</artifactId>
       <version>${jersey.version}</version>
       <scope>test</scope>
   </dependency>
   <dependency>
       <groupId>org.glassfish.jersey.inject</groupId>
       <artifactId>jersey-hk2</artifactId>
       <version>${jersey.version}</version>
       <scope>test</scope>
   </dependency>
</dependencies>

Now when I change the version to 3.0.0 I get dependency errors. I am trying to follow the Chapter 2 of Modules and dependencies of the jersey user guide but I am not able to resolve to the correct dependencies.

What are the correct jersey dependencies to reference in the POM for Jersey 3x ?


Solution

  • Jersey 3.x requires the new jakarta.* namespace from the Jakarta EE 9 "Big Bang".

    Jetty 9.x is Servlet 3.1.0 which is javax.servlet.* namespace.

    You have to use Jetty 11 for the Jakarta EE 9 namespace changes.