eclipseservlets

Eclipse complains 'The superclass "jakarta.servlet.http.HttpServlet" was not found' even though I'm using a Servlet 3.0 project and Tomcat 9.0 server


I am picking up an old project which has a lot of old dependencies. I am using "Eclipse IDE for Enterprise Java and Web Developers". After importing the source to Eclipse, Eclipse is complaining all my jsp files that

The superclass "jakarta.servlet.http.HttpServlet" was not found on the Java Build Path

In pom.xml, I see there is this dependency:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
</dependency>

I went to google about the error and read a bit of javax vs jakarta history. The thing is, because this is an old project that is still running on the server... can I stick with javax and not jakarta?

In Eclipse, under Project Facets, I have "Dynamic Web Module" checked and it is using Apache Tomcat v9.0 locally. Under Server settings, I have "Tomcat v9.0 Server" at localhost for running this project.

Another thing I don't know if it has anything to do with setup of my Tomcat or project settings, which is that on pom.xml, I get an error about missing a lot of artifacts, like "jini:jsk-lib:jar", "jini:reggie:jar", "jini:start:jar", etc...


Solution

  • can I stick with javax and not jakarta?

    Yes, certainly you can stick with the javax. naming rather than migrating to the new jakarta. namespace. Eventually you’ll want to make the migration to benefit from new and improved technologies. But not necessary this year or next.

    Read the Which version? documentation page. You will see that versions 9.0.x and 10.0.x are functionally equivalent, developed in parallel. The only significant difference is that namespace change discussed above. So use Tomcat 9 if you choose to stick with javax naming.

    You’ll need to get your codebase in order, to use only the javax. naming. Apparently you have some code that refers to the new jakarta. naming. Fix that. Check your import statements. Check any use of fully-qualified class names. Use your IDE’s search tools.

    By the way… If using Tomcat 9, you can change that dependency on the Servlet API from 3.0.1 to the version 4.0.3 of the Servlet specification. See that Which version? page linked above, as well as the https://Jakarta.EE site, to learn the appropriate versions of specs for JSPs, etc. Look for the versions tied to Jakarta EE 8.