Description
When I develop my java project I use:
Java version: 1.8
,
Apache Tomcat version 9.0.x
Then, I use Tomcat 10.0.x
to run my project (with few modifications in my project). I had to change javax
package related imports to jakarta
package imports.
When I build the project I got this following error;
java: cannot access javax.servlet.ServletException
class file for javax.servlet.ServletException not found
Fix
When I search for a fix, I found that I need to include Java Servlet API
dependency in my pom.xml
file. This way I could build the project successfully.
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
Question
- Why do I have to include
Java Servlet API
dependency when I migrate to Tomcat 10 ? - I did include
Java Servlet API
dependency, but is that a proper fix?
jakarta.servlet-api
version 5 or higher. – Homoousian