Maven依赖关系在WEB-INF / lib中不可见 [英] Maven dependencies not visible in WEB-INF/lib

查看:167
本文介绍了Maven依赖关系在WEB-INF / lib中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个奇怪的问题使我的项目基于Maven。我在Eclipse中创建了一个新的 Maven 项目,并启用了动态Web面。但是在运行时,它会抛出 ClassNotFoundException ,因为Maven依赖不会被复制到 WEB-INF / lib 目录。我甚至尝试在POM中添加副本依赖项部分,但没有帮助。



有人这里似乎已经解决了这个正确的方法,但我猜他忘了提及解决方案::(

解决方案

这应该与eclipse和m2eclipse无关,并且可以更好地支持 - m2e-wtp 另外,你不需要复制依赖关系原因:




  • 您应该调用 mvn package (或右键单击> maven>包),并获得一个战争文件 - < packaging> (在pom中)必须是 war

  • 您的依赖关系应与默认范围(如果它们是提供测试不会包含在档案中)

  • 如果你是将项目作为动态Web项目运行在eclipse中的服务器上,然后打开项目属性(右键单击>属性),然后选择部署程序集。点击添加,选择构建路径条目,并选择maven依赖关系。这将指示WTP将maven依赖关系发送到服务器目录。


I'm having this weird problem making my project Maven-based. I created a new Maven project in Eclipse and enabled the Dynamic Web facets. But during runtime now it throws ClassNotFoundException because the Maven dependencies are not copied to WEB-INF/lib directory. I even tried adding the copy-dependencies section in POM, but it didn't help.

Someone here seemed to have solved this the right way, but I guess he forgot to mention the solution ::(

解决方案

This should have nothing to do with eclipse and m2eclipse, and optionally for better support - m2e-wtp. Also, you don't need copy-dependencies. Here are a few possible reasons:

  • you should invoke mvn package (or right-click > maven > package) and obtain a war file - the <packaging> (in the pom) must be war
  • your dependencies should be with the default scope (if they are provided or test they will not be included in the archive)
  • if you are running the project as dynamic web project on a server within eclipse, then you should open the project properties (right click > properties) and select "Deployment Assembly". There click "add", select "build path entries", and choose "maven dependencies". This will instruct WTP to send the maven dependencies to the server dir.

这篇关于Maven依赖关系在WEB-INF / lib中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆