ClassNotFoundException with Maven dependency system scoped

ezy :

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

enter image description here

But when I deploy the app the dependency is missing

java.lang.NoClassDefFoundError: com/novell/ldap/LDAPException
davidxxx :

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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=471743&siteId=1