Maven 依赖项在 WEB-INF/lib 中不可见
我在使我的项目基于 Maven 时遇到了这个奇怪的问题。我在 Eclipse 中创建了一个新的 Maven 项目并启用了动态 Web 方面。但在运行时,它会抛出 ClassNotFoundException
因为 Maven 依赖项未复制到 WEB-INF/lib
目录。我什至尝试在 POM 中添加复制依赖项部分,但没有帮助。
有人这里似乎已经以正确的方式解决了这个问题,但我猜他忘了提及解决方案::(
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 ::(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
这应该与 eclipse 和 m2eclipse 无关,并且可以选择获得更好的支持 - m2e-wtp。此外,您不需要复制依赖项。以下是一些可能的原因:
mvn package
(或右键单击 > maven > package)并获取一个 war 文件 -
(在 pom 中)必须是war
provided
或test
它们将不会包含在 。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
(or right-click > maven > package) and obtain a war file - the<packaging>
(in the pom) must bewar
provided
ortest
they will not be included in the archive)首先安装 Maven Integration For Eclipse WTP (Help->Eclipse Marketplace)
然后在你的 web 项目的 pom.xml 中添加:
之后右键单击该项目,Maven ->更新项目,这会自动在部署程序集中为您添加 Maven 依赖项。
First install Maven Integration For Eclipse WTP (Help->Eclipse Marketplace)
Then in your web project's pom.xml just add:
After that just right click the project, Maven -> Update Project, which should automagically add Maven Dependencies for you in the Deployment Assembly.
右键单击项目>梅文>更新Maven项目>好的,帮我修好了
Right-click project > Maven > Update Maven Project > OK fixed it for me
检查项目的部署程序集属性。我看到一些
mvn eclipse:eclipse
生成的 Eclipse 项目有时会将资产部署到错误的位置。据我所知,新的部署程序集与早期版本的 Eclipse 3.6 (Helios) 存在一些问题。Check the Deployment Assembly property of the project. I have seen some
mvn eclipse:eclipse
generated Eclipse projects sometimes have the assets being deployed to the wrong location. From what I can remember the new Deployment Assembly had some issues with earlier versions of Eclipse 3.6 (Helios).我刚刚做了maven ->更新项目对我有用。
I just did maven -> update project worked for me.
在 Eclipse 上,选择您的 Web 项目 ->右键单击->属性->部署组装->添加-> Java 构建路径条目 -> Maven 依赖关系
通过此步骤,完整发布时,maven 库将包含在 WEB-INF/lib 中。
On Eclipse, select your Web Project -> right click -> Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Maven Dependencies
With this steps, maven libraries will be included on WEB-INF/lib when full publish.
您想使用 copy-dependencies 插件
请参阅此帖子和 文档
you want to use the copy-dependencies plugin
see this post and the docs
如果您查看部署并发现 WEB-Inf/lib 没有 Maven 依赖项,那么确保这些 Maven 依赖项位于您的部署程序集中至关重要,正如所选答案中提到的那样。
然而要小心 Eclipse,即使使用 Maven 更新也不会刷新所有内容。如果您清理、重建和重新部署,但仍然没有看到 lib 文件夹被填充,请尝试通过“服务器”>“添加和删除”删除应用程序并将其重新添加到服务器部署中。
这为我疏通了系统。
If you look into your deployment and see that WEB-Inf/lib is empty of your Maven dependencies, then ensuring those Maven dependencies are in your deployment assembly is crucial as mention in the chosen answer.
However be wary of Eclipse then not refreshing everything even with a Maven update. If you clean, rebuild and redeploy and still do not see the lib folder being populated try removing and re-adding the application to the server deployments via Servers>Add and Remove.
This unclogged the system for me.
右键项目->部署组装:
查看是否有 Maven 依赖项和所有其他依赖项。
如果不,
右键项目-> Maven->启用工作区解析
(也许然后是 Maven -> 更新项目,但然后再次查看“部署程序集”并查看您得到了什么。)
这为我解决了(终于!)。
Right-click project -> Deployment Assembly:
See if you have the Maven Dependencies and all others in there.
If not,
Right-Click project -> Maven -> Enable Workspace Resolution
(maybe then Maven -> Update Project, but then look again into "Deployment Assembly" and see what You've got.)
this solved it (finally!) for me.