部署程序集中的 target/m2e-wtp/web-resources 是什么?

What is target/m2e-wtp/web-resources in Deployment Assembly?

我在Eclipse中使用Maven创建了一个webapp项目,我发现在"Deployment Assembly"配置卡中有一个名为target/m2e-wtp/web-resources的文件夹。这个来源代表什么?我应该保留它还是删除它?

首先,您拥有此条目意味着您的 Eclipse 工作正常。您已正确安装 M2Eclipse 和 m2e-wtp

M2Eclipse是一个将Maven集成到Eclipse中的项目。它提供了直接在 Eclipse 中构建项目的能力(以及许多其他东西)。 m2e-wtp 是 M2E 的一个子集,专注于与 Eclipse Web 工具项目的集成,因此它与 JavaEE 项目结合使用。

当我说 "integrating" 时,它确实意味着幕后发生了很多魔术,使一切顺利进行。 m2e-wtp 的神奇成分之一是 target/m2e-wtp-web-resources 文件夹,当您在 Eclipse 本身中部署 Web 应用程序时会用到该文件夹​​。引用自 documentation:

target/m2e-wtp/web-resources/ is a folder containing automatically generated resources, that need to be deployed on the application server. These generated resources are :

  • pom.properties and MANIFEST.MF generated by the mavenarchiver plugin
  • resources defined in the <webResources> section of the maven-war-plugin's configuration, or filtered web.xml

The target/m2e-wtp/web-resources/ is derived. In Eclipse lingo, it means it'll display a warning if you try to manually edit the files it contains, as they'll most likely be overridden automatically in the next (incremental or not) project build.

If you look in your <project>/.settings/org.eclipse.wst.common.component file, you will see /target/m2e-wtp/web-resources is defined BEFORE the regular war source directory :

<project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="webapp">
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
    <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
    <wb-resource deploy-path="/" source-path="/src/main/webapp"/>
    <property name="context-root" value="webapp"/>
    <property name="java-output-path" value="/webapp/target/classes"/>
  </wb-module>
</project-modules>

The rationale behind this order is, if two files from two different source folders collide, WTP will deploy the first one it finds. So if you filter your web.xml sitting under src/main/webapp/WEB-INF, you will want the filtered version to be deployed on the server, that is target/m2e-wtp/web-resources/WEB-INF/web.xml. If, for some reason, you would like to disable the use of target/m2e-wtp/web-resources/, well, know that you can.

所以,不用担心,该文件夹的存在实际上表明您的设置一切正常。如果您错误地删除了该条目,下次您在 Eclipse 中更新您的 Maven 项目时将重新创建它。