开发者

How to copy dependencies into WEB_INF/lib folder in Spring project with Maven?

I have a Spring MVC project in Eclipse Galileo. Its depenedencies are specified in pom.xml. When I type mvn e开发者_JS百科clipse:eclipse, depenedencies are specified as links in Eclipse build path. But when I try to run this app on server (in Eclipse, run -> run on server) the dependencies do not exist in the class path and that's why I get classDefNotFound error. Is there any way to fix this problem?

Thanks a lot!


How to copy dependencies into WEB_INF/lib folder in Spring project with Maven?

There is no need to do that. And that would just be an horrible workaround. Fix the root cause of the problem.

I have a Spring MVC project in Eclipse Galileo. Its dependencies are specified in pom.xml. When I type mvn eclipse:eclipse, dependencies are specified as links in Eclipse build path.

Weird, that's not what I get. Can you show the content of your .classpath? A typical .classpath generated by the Maven Eclipse Plugin looks like this:

<classpath>
  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
  ...
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

I don't see any "link" here. Is M2_REPO defined in your environment?

But when I try to run this app on server (in Eclipse, run -> run on server) the dependencies do not exist in the class path and that's why I get classDefNotFound error

I think something else is wrong. But copying dependencies into WEB-INF/lib is certainly not the right way to fix the problem.


I suggest that you take a look at M2Eclipse. It provides a classpath container with the project's maven dependencies and has generally better integration with Eclipse.

How to copy dependencies into WEB_INF/lib folder in Spring project with Maven?

Its main features are:

  • Creating and importing Maven projects
  • Dependency management and integration with the Eclipse classpath
  • Automatic dependency downloads and updates
  • Artifact Javadoc and source resolution
  • Creating projects with Maven Archetypes
  • Browsing and searching remote Maven repositories
  • POM management with automatic update to dependency list
  • Materializing a project from a Maven POM
  • Checking out a Maven project from several SCM repositories
  • Adapting nested multi-module Maven projects to the Eclipse IDE
  • Integration with Web Tools Project (WTP)
  • Integration with Subclipse and Subversive
  • Integration with Mylyn
  • Form-based POM Editor
  • Graphical Display of Dependency Graphs
  • GUI Presentation of Dependency Tree and Resolved Dependencies

The maven-eclipse-plugin is scheduled to be deprecated and later on retired so it would be wise to look into something which will be maintained in the near future.


I had a similar issue with a maven project on IRAD. Right click on the War project, select properties. Under 'Java EE Module Dependencies' select the check box besides 'Maven Dependencies'. This should copy the lib folder to the target location on server during deploy.

I am Using IRAD, so not sure if this is specific to IRAD or is available on Eclipse.


Since you seem to have a maven project, you could use Eclipse Maven Plugin (M2Eclipse) and import the project as a Maven project

That said, the steps followed above should have worked as well.


Did you add the MAVEN_REPO classpath variable to Eclipse? If not, you can use the maven plugin to do so:

mvn -Dworkspace=/path/to/your/workspace eclipse:configure-workspace

Take a look at the Usage page of the maven-eclipse-plugin for details!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜