SUBIN K SOMAN
SUBIN K SOMAN

Reputation: 406

Java ClassNotFoundException with maven dependency?

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>upload</groupId>
    <artifactId>upload</artifactId>
    <scope>system</scope>
    <version>1.0</version>
    <systemPath>${basedir}\lib\upload.jar</systemPath>
</dependency>

This added the relevant JAR file to my Maven Dependencies folder in Eclipse. I can access the classes in code but I get the mentioned exceptions once I run the application.

The jar is referenced in my Java build path under Maven dependencies:

when i am running the project am getting following exception

java.lang.NoClassDefFoundError: 

Upvotes: 0

Views: 6147

Answers (1)

Jesper
Jesper

Reputation: 206776

That is because you set the scope to system. When you do that, Maven assumes that you are taking care yourself that the jar is on the classpath when you run it.

From the Maven documentation:

  • system This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

If you have a jar file which is not available in for example the Maven Central repository and you don't want to use system scope, then install the jar in your local Maven repository; see Guide to installing 3rd party JARs. After you've done that, you can use a normal dependency with compile scope.

Upvotes: 2

Related Questions