Junit do not find system scope dependency

28 Views Asked by At

I'm trying to create unit tests for a project that uses Maven. When I run my test, it throws this exception while trying to read a dependency named ENV.

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

This is how this dependency looks like in my POM.xml

<dependency>
    <groupId>ENV</groupId>
    <artifactId>ENV</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${pathEnviroment}</systemPath>
</dependency>

JUnit does not behave this way with my other dependencies that are added to my local repository. So, I removed the scope and systemPath tags and added ENV to my local repository, but the test keeps throwing the same exception. Could someone please help me?

Additional information that could help: I have a manifest file to make this dependency work in the .jar that I generate of the project.

1

There are 1 best solutions below

0
Akzy On

Here are some steps to troubleshoot and resolve the issue:

  1. Check the ENV Dependency: Ensure that the ENV dependency is correctly installed in your local Maven repository. You mentioned that you added it to your local repository, so verify that it is installed properly.
  2. Check the systemPath: If you are using the system scope for the ENV dependency, make sure that the systemPath specified in the POM.xml is correct and points to the location of the ENV JAR file on your system
  3. Check the NoClassDefFoundError: The NoClassDefFoundError for org.slf4j.LoggerFactory indicates that the SLF4J library is not being found at runtime. Ensure that the SLF4J library is included as a dependency in your project's POM.xml. You can add the SLF4J dependency.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.32</version> <!-- Use the latest version -->
</dependency>

  1. You mentioned that you have a manifest file to make the ENV dependency work in the generated JAR. Ensure that the manifest file is correctly configured to include the ENV dependency and its dependencies in the Class-Path attribute.

  2. After making any changes to the POM.xml, run the Maven command to update the project and its dependencies:


`bash`
`mvn clean install`