Notification texts go here Contact Us Buy Now!

Can't locate import javax.inject.Inject package

Dagger leverages JSR 330, the Java standard annotations utilized for dependency injection. These annotations encompass @Inject, @Singleton, and more. To integrate this feature, you'll need to include a separate jar file.

For projects employing a build system with integrated dependency management, this inclusion is handled automatically. However, if you're manually managing jar files, you'll need to add it yourself.

To obtain the latest jar, navigate to Maven central: Maven central and scroll to the bottom of the page.

Add to pom.xml:

<dependency>
    <groupId>javax.inject</groupId>
    <artifactId>javax.inject</artifactId>
    <version>1</version>
</dependency>

Adding the Jar File in Java Projects:

For those working with plain Java projects (without Maven, Gradle, or similar tools), you can download a separate Jar file from here.

Once downloaded, add it to your external libraries. In IntelliJ IDEA, follow these steps:

  1. Select "File" > "Project Structure."
  2. Navigate to "Libraries" and click the "+" icon to add a new project library.
  3. Locate the downloaded Jar file and select it.

For Dependency Injection:

implementation "com.google.dagger:dagger:$rootProject.dagger2Version"

Inject via Maven:

  1. Select "File" > "Project Structure" > "Project Settings" > "Libraries" > "Add" > "From Maven."
  2. Search for javax.inject:javax.inject:1.
  3. Click "OK" once found.

Adding to Gradle:

implementation 'javax.inject:javax.inject:1'

JakartaEE 10 and Above:

In Jakarta EE 10, javax.inject has moved to the jakarta namespace. To retrieve the Inject class, use the dependency: https://mvnrepository.com/artifact/jakarta.inject/jakarta.inject-api

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.