Java.lang.NoClassDefFoundError: in eclipse maven

In eclipse with maven, I add the dependency as a local jar file, like this:

<dependency> <groupId>xyz-core</groupId> <artifactId>xyz-core</artifactId> <version>0</version> <scope>system</scope> <systemPath>/home/xyz/xyz-core.jar</systemPath> </dependency> 

In this jar file, I have an interface that is used in my application.

When I run my application on the tomcat server, it shows an exception for this interface

 Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.NoClassDefFoundError: com/mxgraph/canvas/mxICanvas2D 

and mxICanvas2D is the interface.

+7
java spring eclipse maven
source share
3 answers

This is most likely because you specified the system scope. According to the Maven documentation :

system

This area is similar to provided , except that you must provide a JAR that contains this explicitly. The artifact is always available and cannot be viewed in the repository.

In other words, the dependency does not fit into your class path when the application starts, if you use system ; you have to do it yourself.

Use one of the other areas, for example compile .

+11
source share

Have you added "Maven Dependencies" to the "Web Deployment Assembly" project. If not, add the following:

Right click on your project -> Properties -> Deployment Build -> Add -> Java Build Path Entries -> Next, and then from there you can add "maven Dependencies". Then create and try to run the application.

+5
source share

Since you are using the system area, this means that maven will use this to compile your project, you will not see your mistakes, however, when you use an application in tomcat that is not connected with maven and tomact, it does not know where your dependencies are, one one of the ways to solve it is to copy the necessary .jars to your tomcat / lib folder .

Usually you need to provide or compile a scope, but these areas are used if you have a repository. When you create a new mavenized project and then create it, maven will create a .jar for this particular dependency on your local machine (c: /users/user/.m2/repository/). This will work for your own projects.

+1
source share

All Articles