Getting java.lang.ClassNotFoundException: jakarta.servlet.Filter on Maven/Jersey web service while running on Tomcat 9

前端 未结 3 1097
情深已故
情深已故 2020-12-11 10:34

I am new in jakarta EE /webservice. While running on Tomcat 9 server with the following resource, I am getting error java.lang.ClassNotFoundExceptio

3条回答
  •  盖世英雄少女心
    2020-12-11 10:47

    java.lang.ClassNotFoundException: jakarta.servlet.Filter

    This class is part of Servlet API version 5.0 which in turn is part of Jakarta EE version 9.

    And,

    3.0.0-M6
    

    this Jersey version is based off JAX-RS API version 3.0 which in turn is part of Jakarta EE version 9.

    And,

    Tomcat 9 server

    this Tomcat version is based off Servlet API version 4.0 which in turn is part of Java/Jakarta EE version 8.

    So, summarized, the targeted JEE versions don't match up and it's causing trouble for you. You have 2 options:

    1. Downgrade Jersey to version 2.x. This one is based off JAX-RS API version 2.x which in turn is part of Java/Jakarta EE version 8.

    2. Or, upgrade Tomcat to version 10.x. This one is based off Servlet API version 5.0 which in turn is part of Jakarta EE version 9 (which in turn offers JAX-RS API version 3.x for which you can thus use the intended Jersey version).

    The technical reason is that during the step from Java/Jakarta EE 8 to Jakarta EE 9 all javax.* packages have been renamed to jakarta.* packages. So there is no backwards compatibility anymore since Jakarta EE 9. The target runtime itself (thus, Tomcat itself), has really to be the one targeted for the APIs in use by Jakarta EE 9.

    See also:

    • Apache Tomcat - Versions

提交回复
热议问题