0

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: 
3
  • i tried provided and compile also Commented Dec 18, 2014 at 12:48
  • 1
    Which class is missing? Commented Dec 18, 2014 at 12:50
  • This jar is in the correct path? ${basedir} is well defined? The class name you are using is correctly typed? Commented Dec 18, 2014 at 12:52

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.