java - Deployment Assembly 中的 target/m2e-wtp/web-resources 是什么?

标签 java eclipse maven m2e-wtp

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

Deployment Assembly

最佳答案

首先,您拥有此条目的事实意味着您的 Eclipse 运行顺利。你有 M2Eclipse 和 m2e-wtp正确安装。

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

当我说“集成”时,它实际上意味着在幕后发生了很多魔法,使一切顺利进行。 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 项目时将重新创建它。

关于java - Deployment Assembly 中的 target/m2e-wtp/web-resources 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35525117/

相关文章:

c - 在 Eclipse 中处理自定义 makefile 时出现问题

java - 配置maven插件cxf-codegen-plugin以忽略安全问题

java - 运行我的第一个 Java 应用程序时出现 InvalidModuleDescriptorException

java - 在 Coldfusion 中使用 CFIMAP 获取最新邮件

java - 在 gremlin 服务器脚本文件中使用自定义库

Python self 在类定义级别的 lambda 中,Eclipse 咆哮,但解释器可以工作,这是标准化的吗?

Eclipse(3.5)如何水平比较文件?

maven - 如何在 Artifactory 中重建 maven-metadata.xml?

maven - 带有 spring-boot 的自定义 sql 中的 Liquibase 参数

java - Java 中带有新行的自定义异常消息