Eclipse 中的 Maven 项目 - 部署程序集构建失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6799135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:21:15  来源:igfitidea点击:

Maven project in eclipse - deployment assembly fails build

eclipsedeploymentmaven

提问by Vishal

Sorry for being verbose...

抱歉啰嗦了...

I have some existing maven projects. I imported them into Eclipse using Maven -> Import existing Maven projects.

我有一些现有的 Maven 项目。我使用Maven -> 导入现有的 Maven 项目将它们导入到 Eclipse 中

This gave me 6 individual projects and one project which lists all 6 under it. (The umbrella project has 6 modules defined in it which translated to 6 eclipse project - as I understand how maven works)

这给了我 6 个单独的项目和一个列出所有 6 个项目的项目。(伞形项目中定义了 6 个模块,它们转换为 6 个 eclipse 项目——据我所知,maven 是如何工作的)

One of the project A requires two other project B and C (at compile time and run-time).

项目 A 之一需要另外两个项目 B 和 C(在编译时和运行时)。

Build path - On the build path of A I have one of the libraries as Maven dependencies. And it builds fine.

构建路径 - 在 AI 的构建路径上,将其中一个库作为 Maven 依赖项。它构建得很好。

Deployment assembly - On the deployment assembly of A however there is no entry for deploy to web-inf/lib. Because of that when tomcat starts it doesn't find any required jars or the project B and C. So I added an entry to deployment assembly as : source - maven And dependencies deploy - web-inf/lib. Tomcat comes up and my webapp for project A comes up.

部署程序集 - 然而,在 A 的部署程序集上没有部署到 的条目web-inf/lib。因此,当 tomcat 启动时,它找不到任何必需的 jars 或项目 B 和 C。所以我在部署程序集中添加了一个条目:source - maven 和依赖项部署 - web-inf/lib。Tomcat 出现了,我的项目 A 的 webapp 出现了。

This however breaks the eclipse build - upon build eclipse complains: "Invalid classpath publish export Project entries not supported"

然而,这破坏了 eclipse 构建 - 在构建时 eclipse 抱怨: “不支持无效的类路径发布导出项目条目”

This I see is because, under build path, there is new entry added to web-inf/lib to publish/export under maven-dependencies. Removing that removes maven entry from the deployment assembly as well.

我看到这是因为,在构建路径下,有新条目添加到 web-inf/lib 以在 maven-dependencies 下发布/导出。删除它也会从部署程序集中删除 maven 条目。

The only workaround is that in the deployment assembly I specify the web-inf/libunder target generated by maven but that causes stale copies of project B and C to be picked up.

唯一的解决方法是在部署程序集中我指定了web-inf/lib由 maven 生成的下目标,但这会导致项目 B 和 C 的陈旧副本被拾取。

Why I need this setting is because when I make changes to project B and C in Eclipse and build them in Eclipse I want to see the changes when I am debugging project A. I don't want to run maven builds on B and C again since its time consuming.

为什么我需要这个设置是因为当我在 Eclipse 中对项目 B 和 C 进行更改并在 Eclipse 中构建它们时,我想在调试项目 A 时看到更改。我不想再次在 B 和 C 上运行 maven 构建因为它耗时。

Any help is much appreciated.

任何帮助深表感谢。

I did try including the MAVEN2_CLASSPATH_CONTAINERbut that is always empty and when tomcat runs it cannot find the necessary libraries. (BTW what vale is the MAVEN2_CLASSPATH_CONTATINERset to?)

我确实尝试包括MAVEN2_CLASSPATH_CONTAINER但它总是空的,当 tomcat 运行时,它找不到必要的库。(顺便说一句,MAVEN2_CLASSPATH_CONTATINER设定值是什么?)

This is on Eclipse Indigo Mac OSX.

这是在 Eclipse Indigo Mac OSX 上。

采纳答案by dntbrme

For anyone else that searches for this, it seems that you can also manually add the following to the .classpath file

对于搜索此内容的其他任何人,您似乎还可以手动将以下内容添加到 .classpath 文件中

<classpathentry combineaccessrules="false" kind="src" path="/B"/>

回答by David B

You need to add the relevant project/s to your Deployment Assembly.

您需要将相关项目添加到您的部署程序集中。

Right Click Project -> Properties -> Deployment Assembly -> Add

右键单击项目 -> 属性 -> 部署程序集 -> 添加

回答by Ciro Alvino

I solved just doing this:

我解决了这样做:

right click on my eclipse project-> Maven -> Update Project Configuration...

右键单击我的 Eclipse 项目-> Maven -> 更新项目配置...

回答by Vishal

Figured it out ..but not completely...

想通了..但不完全......

So I added maven dependencyin the deployment assembly as I mentioned earlier.

所以我在部署程序集中添加了maven 依赖项,正如我之前提到的。

Maven dependency -> WEB-INF/lib

AND additionally added project Band Cas well :

并且还额外添加了项目 BC

B -> WEB-INF/lib and C->WEB-INF/lib

Somehow this way B and C are not added to the publish/export in the java build path. I don't know how eclipse knows to not export B and C from maven repo but to export it from project B and C itself.

不知何故,B 和 C 不会被添加到 java 构建路径中的发布/导出中。我不知道 eclipse 怎么知道不从 maven repo 导出 B 和 C,而是从项目 B 和 C 本身导出它。

Anyways thats for some other day.. for now i m happy :)

反正那是前几天的事了..现在我很高兴:)

回答by Parag Arora

By including Maven Dependencies, you are including dependencies for project B and project C. It turns out, you also have to include project B and C manually.

通过包含 Maven 依赖项,您将包含项目 B 和项目 C 的依赖项。事实证明,您还必须手动包含项目 B 和 C。

The exact fix which works is. project A -> properties -> Deployment Assembly

有效的确切修复方法是。项目 A -> 属性 -> 部署程序集

Click Add and then Project. Select B and C. Problem will get fixed after rebuilding.

单击添加,然后单击项目。选择 B 和 C。问题将在重建后得到解决。

回答by Manmohan Bohara

This error can occur if you have multiple entries of same jar in you class path. So you need to check your classpath and remove duplicate entries.

如果您的类路径中有多个相同 jar 的条目,则可能会发生此错误。所以你需要检查你的类路径并删除重复的条目。

回答by Muel

I had this problem, but I believe none of these answers correctly fix the problem. Instead they workaround m2eclipse (which should manage classpaths and deployment assembly for you). For me, the problem that I was using m2eclipse without m2eclipse-wtp (a separate plugin).

我遇到了这个问题,但我相信这些答案都不能正确解决问题。相反,他们解决了 m2eclipse(它应该为您管理类路径和部署程序集)。对我来说,我在没有 m2eclipse-wtp(一个单独的插件)的情况下使用 m2eclipse 的问题。

See this SO answerfor the plug-in details.

有关插件详细信息,请参阅此 SO 答案

回答by manutudescends

You can add the relevant projects / or maven java build path entry if using maven to your Deployment assembly (project -> properties -> deployment Assembly)

如果使用 maven 到您的部署程序集(项目 -> 属性 -> 部署程序集),您可以添加相关项目/或 maven java 构建路径条目

Then checks if theses relevant project are Facets compatible. (project -> Project Facets)

然后检查这些相关项目是否与 Facets 兼容。(项目 -> 项目方面)