Maven 依赖项在 WEB-INF/lib 中不可见

发布于 2024-11-08 17:27:22 字数 328 浏览 0 评论 0原文

我在使我的项目基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

家住魔仙堡 2024-11-15 17:27:22

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

  • 您应该调用 mvn package (或右键单击 > maven > package)并获取一个 war 文件 - (在 pom 中)必须是 war
  • 您的依赖项应该具有默认范围(如果它们是 providedtest 它们将不会包含在 。
  • 如果您在 Eclipse 中的服务器上将项目作为动态 Web 项目运行,那么您应该打开项目属性(右键单击 > 属性)并选择“部署程序集” 单击“添加”,选择“构建路径条目”,然后选择“maven 依赖项”。这将指示 WTP 将 Maven 依赖项发送到服务器目录。

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.
み格子的夏天 2024-11-15 17:27:22

首先安装 Maven Integration For Eclipse WTP (Help->Eclipse Marketplace)

然后在你的 web 项目的 pom.xml 中添加:

    <packaging>war</packaging>

之后右键单击该项目,Maven ->更新项目,这会自动在部署程序集中为您添加 Maven 依赖项。

First install Maven Integration For Eclipse WTP (Help->Eclipse Marketplace)

Then in your web project's pom.xml just add:

    <packaging>war</packaging>

After that just right click the project, Maven -> Update Project, which should automagically add Maven Dependencies for you in the Deployment Assembly.

心凉怎暖 2024-11-15 17:27:22

右键单击项目>梅文>更新Maven项目>好的,帮我修好了

Right-click project > Maven > Update Maven Project > OK fixed it for me

锦上情书 2024-11-15 17:27:22

检查项目的部署程序集属性。我看到一些 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).

拿命拼未来 2024-11-15 17:27:22

我刚刚做了maven ->更新项目对我有用。

I just did maven -> update project worked for me.

九八野马 2024-11-15 17:27:22

在 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.

残疾 2024-11-15 17:27:22

您想使用 copy-dependencies 插件

请参阅帖子和 文档

you want to use the copy-dependencies plugin

see this post and the docs

淡墨 2024-11-15 17:27:22

如果您查看部署并发现 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.

假面具 2024-11-15 17:27:22

右键项目->部署组装:
查看是否有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文