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.
Here are some steps to troubleshoot and resolve the issue:
ENVDependency: Ensure that theENVdependency is correctly installed in your localMavenrepository. You mentioned that you added it to your local repository, so verify that it is installed properly.systemPath:If you are using the system scope for theENVdependency, make sure that the systemPath specified in the POM.xml is correct and points to the location of the ENV JAR file on your systemNoClassDefFoundError: TheNoClassDefFoundErrorfororg.slf4j.LoggerFactoryindicates that theSLF4Jlibrary is not being found at runtime. Ensure that theSLF4Jlibrary is included as a dependency in your project's POM.xml. You can add theSLF4Jdependency.You mentioned that you have a manifest file to make the
ENVdependency work in the generated JAR. Ensure that the manifest file is correctly configured to include the ENV dependency and its dependencies in theClass-Pathattribute.After making any changes to the
POM.xml, run the Maven command to update the project and its dependencies: