I am getting ClassNotFoundException
and NoClassDefFoundError
exceptions when I attempt to run my application using a maven defined dependency.
I added my maven dependency for the jar in question to my pom.xml file with the following declaration:
<dependency>
<groupId>ldap</groupId>
<artifactId>com.novell.ldap</artifactId>
<systemPath>${local.lib.dir}/ldap.jar</systemPath>
<scope>system</scope>
<version>1</version>
</dependency>
The jar is correctly added to the Dependencies NetBeans project
But when I deploy the app the dependency is missing
java.lang.NoClassDefFoundError: com/novell/ldap/LDAPException
Dependency scopes can help to limit the transitivity of the dependencies. They also modify the classpath for different build tasks. Maven has six default dependency scopes. And it's important to understand that each scope — except for import — has an impact on transitive dependencies.
Dependency scope is used to limit the transitivity of a dependency and to determine when a dependency is included in a classpath. There are 6 scopes: compile. This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project.
<dependencyManagement> allows to consolidate all dependencies (used at child pom level) used across different modules -- clarity, central dependency version management.
If you read the Maven documentation about this scope, it seems the expected behavior if your application server doesn't provide this library at runtime:
This scope is similar to provided except that you have to provide the JAR which contains it explicitly.
The provided
scope states :
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime.
Not advised solution : add this library in the lib folder of your application server.
Cleaner solution : add this maven dependency in your maven repositories manually or with mvn install:install-file
.
And remove the system
scope of this dependency. It will use the default
scope.
The system scope in maven is somewhat like provided, that is dependency is used only at compile time. It 's your responsability to make sure that jar is in the classpath at runtime.
Besides, the system scope is actually deprecated, consider other alternatives. see introduction to dependency mechanism
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With