Java 部署程序集中缺少 maven 依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31148282/
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-08-11 10:42:44  来源:igfitidea点击:

Missing maven dependencies from deployment assembly

javaeclipsem2eclipsem2e-wtp

提问by Behnil

I've recently upgraded from eclipse 4.4.2 (Luna) to 4.5 (Mars). My dynamic web project now doesn't include the Maven Dependencies in its deployment assembly "Project->Properties->Deployment assembly".

我最近从 eclipse 4.4.2 (Luna) 升级到 4.5 (Mars)。我的动态 Web 项目现在在其部署程序集“项目->属性->部署程序集”中不包含 Maven 依赖项。

I can add them manually (using "Project->Properties->Deployment assembly->Add->Java Build Path Entries->Maven Dependencies"), but every time I run "Project->Maven->Update Project Configuration", the Maven Dependencies are removed again.

我可以手动添加它们(使用“Project->Properties->Deployment assembly->Add->Java Build Path Entries->Maven Dependencies”),但是每次我运行“Project->Maven->Update Project Configuration”时, Maven 依赖项再次被删除。

Note that I run the project using the Apache Tomcat Server within the Eclipse IDE.

请注意,我在 Eclipse IDE 中使用 Apache Tomcat 服务器运行该项目。

I have installed

我已经安装

  • m2e 1.6.0.20150526-2032
  • m2e-wtp 1.2.0.20150602-1740
  • m2e 1.6.0.20150526-2032
  • m2e-wtp 1.2.0.20150602-1740

回答by Jebil

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:

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

  • you should invoke mvn package (or right-click > maven > package) and obtain a war file - the (in the pom) must be war

    <packaging>war</packaging>

  • 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.
  • 您应该调用 mvn package(或右键单击 > maven > package)并获取一个 war 文件 - (在 pom 中)必须是 war

    <packaging>战争</packaging>

  • 您的依赖项应具有默认范围(如果提供或测试它们将不会包含在存档中)

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

回答by Bhupi

can you please try to cleanse setup by following below steps

您可以按照以下步骤尝试清理设置吗

  1. disable Maven nature of application :
  1. 禁用应用程序的 Maven 性质:

Right Click Project -> Maven -> Disable Maven Nature

  1. open cmd , go to project location , Run mvn clean install eclipse:eclipse -Dwtpversion=2.0(This goal just deletes the .project, .classpathand .settings/ files/directories. You can also just remove those files (again while the project is open) instead of running mvn eclipse clean.)

  2. Re-enable the maven nature. (Most of the time, this can be done by right-clicking on the project in question in the package explorer pane, and then choosing 'Configure'-> 'Convert to Maven Project')

  1. 打开 cmd ,转到项目位置,运行mvn clean install eclipse:eclipse -Dwtpversion=2.0(此目标只是删除.project,.classpath.settings/ files/directories。您也可以删除这些文件(再次在项目打开时)而不是运行mvn eclipse clean.

  2. 重新启用 Maven 特性。(大多数情况下,这可以通过在包资源管理器窗格中右键单击相关项目,然后选择 来完成'Configure'-> 'Convert to Maven Project'

other things you can try of

你可以尝试的其他事情

1. reimport project into some other workspace 
2. resintall eclipse 

if it still didn't solve your problem , most probably you might need to raise Jirato eclipse team .

如果它仍然没有解决你的问题,很可能你可能需要提高Jiraeclipse 团队。

回答by Patrick He

I recently had the same issue just like your description above and I got it working this way:

我最近遇到了与您上面的描述相同的问题,我以这种方式工作:

  1. right-click on project > Maven > Disable Maven Nature
  2. right-click on project > Configure > Convert to Maven Project
  1. 右键单击项目 > Maven > 禁用 Maven Nature
  2. 右键单击项目 > 配置 > 转换为 Maven 项目

Then call the Maven update project, the Maven dependencies will not disappear from the view of Deployment Assembly again.

然后调用Maven更新项目,Maven依赖就不会再从Deployment Assembly的视图中消失了。

回答by Hatem Badawi

I solved the same issue this way:

我用这种方式解决了同样的问题:

  1. Open pom.xml and make Packaging war.
  2. Right click the project and select Maven>Update Project.
  1. 打开 pom.xml 并制作 Packaging war
  2. 右键单击项目并选择Maven>Update Project

Will update the project without deleting the Maven Dependencies from Deployment Assembly ; And if the Maven Dependencies is missing the Maven>Update Projectwill automatically add it to the project Deployment Assembly

将更新项目而不从部署程序集中删除 Maven 依赖项;如果缺少 Maven 依赖项,Maven>Update Project则会自动将其添加到项目部署程序集中

回答by David SCHERRER

I solved a similar issue by doing following actions on my web project:

我通过对我的网络项目执行以下操作解决了类似的问题:

  • removing maven nature
  • cleaning up all m2e generated files
  • adding maven nature
  • alt + F5
  • 去除 maven 性质
  • 清理所有 m2e 生成的文件
  • 添加 maven 性质
  • alt + F5

Note : I had this issue after adding maven nature to my java projects in order to use them with m2e instead of prior maven eclipse plugin (legacy...)

注意:在将 maven 性质添加到我的 java 项目后,我遇到了这个问题,以便将它们与 m2e 一起使用,而不是之前的 maven eclipse 插件(遗留...)

回答by Mukul Bansal

What I was doing - I was replacing the default web.xml file with my own web.xml.

我在做什么 - 我用我自己的 web.xml 替换默认的 web.xml 文件。

The moment I replaced my default web.xml (which is created while creating a new maven web project), the Maven Dependencies disappeared from the Deployment Assembly. So, instead of replacing, I copy-pasted my content in the original/default web.xml.

当我替换默认的 web.xml(在创建新的 Maven Web 项目时创建)时,Maven 依赖项从部署程序集中消失了。因此,我没有替换,而是将我的内容复制粘贴到原始/默认 web.xml 中。

That resolved my problem.

那解决了我的问题。

回答by Elias

I resolved this problem as follows;

我如下解决了这个问题;

  1. copy the content of the web.xml file and save it somewhere for later use.

  2. delete the web.xml file.

  3. Right click on the project -> Java EE Tools -> Generate Deployment Descriptor Stub

  1. 复制 web.xml 文件的内容并将其保存在某处以备后用。

  2. 删除 web.xml 文件。

  3. 右键单击项目 -> Java EE Tools -> Generate Deployment Descriptor Stub

step 3 will generate the web.xml file in the WEB-INF folder. then you can paste your saved content in step 1 to the newly generated web.xml file.

第 3 步将在 WEB-INF 文件夹中生成 web.xml 文件。然后您可以将步骤 1 中保存的内容粘贴到新生成的 web.xml 文件中。

After this your maven dependencies will not be removed from the deployment Assembly.

在此之后,您的 Maven 依赖项将不会从部署程序集中删除。

回答by Alex R

In my case, it was a pluginExecutionFilterin the pluginManagementsection in the pom.xml.

就我而言,它位于 pom.xmlpluginExecutionFilterpluginManagement部分中。

Removing the section for org.apache.maven.plugins:maven-war-plugineliminated the problem of the maven dependencies that would vanish from the deployment assembly, along with the issue that after adding the maven dependencies manually, deployment would also install test dependencies:

删除部分 fororg.apache.maven.plugins:maven-war-plugin消除了 maven 依赖项会从部署程序集中消失的问题,以及手动添加 maven 依赖项后,部署还会安装测试依赖项的问题:

                <!-- Remove to eliminate vanishing maven dependencies
                           <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-war-plugin
                                    </artifactId>
                                    <versionRange>
                                        [3.0.0,)
                                    </versionRange>
                                    <goals>
                                        <goal>war</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution> -->

回答by Robert Fornesdale

my case was the following: I wasn't even able to choose the "Maven Dependencies" for the "Deployment Assembly".

我的情况如下:我什至无法为“部署程序集”选择“Maven 依赖项”。

I could finally (!) solve it this way: rightclick on project -> Maven -> Enable Workspace Resolution

我终于可以(!)以这种方式解决它:右键单击项目 -> Maven -> 启用工作区分辨率

watch out again in "Deployment Assembly" (project properties), if it worked.

如果它有效,请在“部署程序集”(项目属性)中再次注意。

回答by roger

My solution was:

我的解决方案是:

Eclipse > Window > Preferences > Maven > Java EE Integration > Check "Enable Java EE configuration"

Eclipse > 窗口 > 首选项 > Maven > Java EE 集成 > 选中“启用 Java EE 配置”