# Fix Java Jakarta Class Not Found NoClassDefFoundError

> Resolve the NoClassDefFoundError for Jakarta servlet classes by updating dependencies from javax to jakarta namespace and verifying application server compatibility

**URL:** https://sentry.io/answers/java-jakarta-class-not-found/

---

## The Problem

You encounter the following error in your Java application:

```java
java.lang.NoClassDefFoundError: jakarta/servlet/http/HttpServletRequest
```

This error occurs when a class that your application needs at runtime is missing or cannot be found on the classpath. Specifically, it indicates that the `jakarta.servlet.http.HttpServletRequest` class could not be found.

## The Solution

This issue often arises when migrating applications to newer versions of Jakarta EE from Java EE or using newer libraries that depend on `jakarta.*` package names instead of the `javax.*` packages.

Let's ensure that your project is fully compatible with Jakarta EE by checking for the following common problems:

- Outdated Jakarta Servlet dependencies
- Compatibility issues in projects built with Java EE
- Incompatible application servers
- References to defunct dependencies and libraries
- Outdated build scripts

### Check Dependencies

Ensure that your `pom.xml` file (for Maven projects) and the corresponding build file for your project management tool contain the correct Jakarta Servlet dependency.

For Jakarta Servlet, you can include the following dependency:

```xml
<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
    <version>5.0.0</version> <!-- Ensure that the version matches your needs -->
    <scope>provided</scope>
</dependency>
```

If you use Gradle, add the following dependency:

```gradle
dependencies {
    compileOnly 'jakarta.servlet:jakarta.servlet-api:5.0.0' // Adjust version as necessary
}
```

**Note:** You can adjust the version based on your Jakarta EE requirements.

### Check Project Compatibility

If your project was originally built using Java EE (`javax.*`) and your application server or libraries were subsequently upgraded to use Jakarta EE (`jakarta.*`), you may encounter compatibility issues. Ensure that all project dependencies, modules, and configurations align with Jakarta EE specifications.

### Check Application Server Compatibility

Check whether the application server supports the version of Jakarta EE used by your application. Some servers are only compatible with Java EE. Using Jakarta dependencies without proper server support may lead to runtime issues.

### Check for Old References

Ensure that there are no outdated dependencies or libraries that still rely on `javax.servlet.*` classes. Such mixed usage can lead to class resolution problems.

### Validate Build Tools and Configurations

If you have a custom build process or use tools like Gradle, ensure that your build scripts reflect the correct dependencies and versions for Jakarta EE.

## Further Reading

- The [Jakarta Servlet](https://jakarta.ee/specifications/servlet/) documentation

---

*Source: [sentry.io/answers/java-jakarta-class-not-found/](https://sentry.io/answers/java-jakarta-class-not-found/)*
