7

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.

Prashant Aggarwal
  • 208
  • 1
  • 7
  • 20
  • You should add a full stacktrace also relevant part of your spring config –  Sep 07 '13 at 07:11

4 Answers4

12

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.

Jesper
  • 202,709
  • 46
  • 318
  • 350
  • it will give error in pom.xml while adding scope as complie Project build error: 'dependencies.dependency.systemPath' for xyz-core:xyz-core:jar must be omitted. This field may only be specified for a dependency with system scope. – Prashant Aggarwal Sep 07 '13 at 07:20
  • Remove the `systemPath` element from the dependency, and [install the dependency](http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html) in your Maven repository instead. – Jesper Sep 07 '13 at 07:24
  • Good! You can click the checkmark at the top left of my answer to accept it as the answer to your question. – Jesper Sep 07 '13 at 08:39
  • 1
    @PhilipRego It doesn't work **for you**, because you have a different problem, apparently. That doesn't mean my answer is bad and doesn't work in general. Note that the OP mentioned it solved his problem... Post a new question and explain your own problem. – Jesper May 31 '17 at 20:54
  • @PhilipRego Yes he did, see the third comment to this answer. And if you don't have `system` in your `pom.xml` then you do not have the same problem. – Jesper Jun 01 '17 at 07:33
  • mine was scope=test .. for some stupid reason the mavenrepository eg dependency had this set. – pstanton Oct 03 '18 at 03:51
8

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.

Debojit Saikia
  • 10,532
  • 3
  • 35
  • 46
1

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.

porfiriopartida
  • 1,546
  • 9
  • 17
0

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

Shadyar
  • 709
  • 8
  • 16