I was working on a maven project in intellij-idea and for some reason decided to change my java language level to 15 from 8 and now it does not recognise the jakarta package that I imported.
I tried using local history to revert the code but it doesn't work either. I tried adding a dependency in pom.xml but the jakarta version is wrong. I don't know how to get the right version as the dependency wasn't there before. What do I do?
Going from Java 8 to Java 15 has no impact on importing from jakarta.*
packages. You have a different problem…
Your problem is specifying version 10.0.0
of the Jakarta Servlet API in your POM’s dependency
element.
👉🏽 There is no Servlet 10 API.
How to know what versions are available?
The current version is 6.0, very soon to be 6.1. Both Servlet 4.0 and Servlet 5.0 are commonly in use as well.
So use one of these in your Maven POM:
<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>4.0.4</version>
<scope>provided</scope>
</dependency>
Certain versions of various app servers support a specific version of the Servlet spec. Choose the Servlet version appropriate to your choice of app server, and appropriate to the features needed by your app.
Thus the error message from Maven saying the dependency could not be found — your specified dependency does not exist.
You may be confused because Jakarta Servlet 6.0 is part of the umbrella specification for Jakarta EE 10. (By the way, note that Jakarta EE 11 with Servlet 6.1 is overdue for release, and should arrive shortly.)
By the way, Java 15 is end-of-life, with no more updating. You should stick to using either:
See Java version history at Wikipedia.
Java releases arrive every six months on strict schedule.
Jakarta EE releases are not yet planned long-term. Likely to be targeted for six months after every Java LTS release.