我在 Eclipse 中使用 Maven 创建了一个 webapp 项目,我发现在“Deployment Assembly”配置卡中有一个名为 target/m2e-wtp/web-resources
的文件夹。这个来源代表什么?我应该保留它还是删除它?
最佳答案
首先,您拥有此条目的事实意味着您的 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
andMANIFEST.MF
generated by the mavenarchiver plugin- resources defined in the
<webResources>
section of themaven-war-plugin
's configuration, or filteredweb.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 undersrc/main/webapp/WEB-INF
, you will want the filtered version to be deployed on the server, that istarget/m2e-wtp/web-resources/WEB-INF/web.xml
. If, for some reason, you would like to disable the use oftarget/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/