In eclipse with maven, I have add a dependency as a local jar file, as 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 a interface that is using in my application.
When I run my application on tomcat server It show exception for that interface
Exception sending context initialized event to listener instance of class
org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: com/mxgraph/canvas/mxICanvas2D
while mxICanvas2D
is a interface.
This is most likely because you have set the scope to system
. According to 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.
In other words, the dependency is not put on your classpath when you run your application if you use system
; you have to do that yourself.
Use one of the other scopes, for example compile
.
Have you added "Maven Dependencies" to the project's "Web Deployment Assembly". If not, add that as follows:
Right Click on your project -> Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Next and then from there you can add "maven Dependencies". Then build and try to run your app.
Since you are using system scope it means that maven will use that to compile your project, you will not see your errors, however, when you are running your application in tomcat, that is not related to maven and tomact does not know where your dependencies are, one way to solve it is copy the needed .jars to your tomcat/lib folder.
Usually you will like to have provided or compile scope, however these scopes are used if you have a repository. When you create a new mavenized project and then build it, maven will create a .jar for that particular dependency in your local machine (c:/users/user/.m2/repository/). That will work for your own projects.
Seldom Maven in Eclipse is not able to clean and build project correctly. It worked for me, follow these steps:
First clean your project by Maven.
In Project Explorer view, Open context menu on the project > Run > Maven Clean
Then build it again.
In Project Explorer view, Open context menu on the project > Run > Maven Build
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.