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

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

问题描述

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

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 ::(

推荐答案

这应该与 eclipse 和 m2eclipse 无关,并且可以选择提供更好的支持 - m2e-wtp.此外,您不需要复制依赖项.以下是一些可能的原因:

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:

  • 您应该调用 mvn package(或右键单击 > maven > package)并获取一个 war 文件 - (在 pom 中)必须是战争
  • 您的依赖项应具有默认范围(如果它们是 providedtest,它们将不会包含在存档中)
  • 如果您在 eclipse 中的服务器上将项目作为动态 Web 项目运行,那么您应该打开项目属性(右键单击 > 属性)并选择部署程序集".单击添加",选择构建路径条目",然后选择maven 依赖项".这将指示 WTP 将 maven 依赖项发送到服务器目录.
  • 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天全站免登陆