migration to Tomcat9, Java17, Jersey, Weld

59 Views Asked by At

I have an existing Java REST service I'm trying to upgrade from Tomcat8, Java8, Jersey(2.23), and Weld(2.4.8). I'm using Weld for CDI so that my service classes get instantiated and injected where they're needed in the resource classes. Everything works fine. I have this project defined as a Gradle7 project currently.

Moving to Java17 seems to have required no changes. Moving to Tomcat9 only required me to change from javax.servlet:javax.servlet-api:3.+ to jakarta.servlet:jakarta.servlet-api:4.+. I'm getting stuck/confused on Jersey and Weld/CDI.

I'm also confused about javax.ws.rs:javax.ws.rs-api:2.+ vs jakarta.ws.rs:jakarta.ws.rs-api:3.+. I'm pretty sure this is related to Jersey though and only requires me to switch my imports from javax to jakarta.

Any direction would be greatly appreciated since I feel like I'm just spinning at this point.

1

There are 1 best solutions below

2
jan.supol On

As Java EE / Jakarta EE evolved, the version of APIs evolved too. At some point the maven artifact names changed from javax to jakarta, and later the java package names moved from java to jakarta. And there were two versions of 8.

| EE Version  | java package names | artifact names | Servlet | JAX-RS |
|-------------|--------------------|----------------|---------|--------|
| Java EE 7   |    javax           | javax          | 3.1     |  2.0   |
| Java EE 8   |    javax           | javax          | 4.0     |  2.1   |
| Jakarta EE 8|    javax           | jakarta        | 4.0.4   |  2.1.6 |
| Jakarta EE 9|    jakarta         | jakarta        | 5.0     |  3.0   |
|Jakarta EE 10|    jakarta         | jakarta        | 6.0     |  3.1   |

See the Tomcat version matrix. There you can find versions of the servlet supported. From that, one can derive the Jersey, CDI, and Weld versions required. The table might look as follows:

| Tomcat | Servlet | javax vs. jakarta | Jersey | JAX-RS | CDI | Weld |
|:------:|:-------:|:-----------------:|:------:|:------:|:---:|:----:|  
|  8.x   |  3.1    | javax             | 2.25.1 |   2.0  | 2.0 | 3.0  |
|  9.x   |  4.0    | javax/jakarta     | 2.26+  |   2.1  |2.0.2| 3.x  |
| 10.0.x |  5.0    | jakarta           | 3.0.x  |   3.0  | 3.0 | 4.x  |
| 10.1.x |  6.0    | jakarta           | 3.1.x  |   3.1  | 4.0 | 5.x  |

Jersey started to support JDK 17 partially since 2.34, better in 2.35.

So you need:

| Tomcat | Servlet                   | JAX-RS                  | Jersey|
------------------------------------------------------------------------
|  9.x   | jakarta.servlet-api:4.0.4 | jakarta.ws.rs-api:2.1.6 | 2.35+ |
|  10.0.x| jakarta.servlet-api:5     | jakarta.ws.rs-api:3.0   | 3.0.x |
|  10.1.x| jakarta.servlet-api:6     | jakarta.ws.rs-api:3.1   | 3.1.x |

Please do not use Jersey 2.35, better start with the fixed latest version.