ezy
ezy

Reputation: 59

ClassNotFoundException with Maven dependency system scoped

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

Upvotes: 7

Views: 11115

Answers (3)

Mathias G.
Mathias G.

Reputation: 5105

The problem is with your maven 'system' scope. It means that the dependency must be available on the application server where the application is deployed (same as scope 'provided'). Scope 'system' has the additional requirement that the dependency must be available as a jar file.

I would recommend to remove the scope element. Like this the dependency will be downloaded into your maven repository and will be available in your generated package file that can be deployed on your application server.

Another solution could be to put the jar file in the library folder of your application server.

Here's a link to the maven documentation concerning this issue.

Upvotes: 0

davidxxx
davidxxx

Reputation: 131496

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.

Upvotes: 4

gtosto
gtosto

Reputation: 1341

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

Upvotes: 1

Related Questions