I created a webapp project using Maven in Eclipse, and I found there is a source named target/m2e-wtp/web-resources
folder in "Deployment Assembly" configuration card. What does this source stand for? Should I keep it or delete it?
First of all, the fact that you are having this entry means that your Eclipse is working smoothly. You have M2Eclipse and m2e-wtp installed correctly.
M2Eclipse is a project that integrates Maven into Eclipse. It provides the ability to build your project directly within Eclipse (and a bunch of other things). m2e-wtp is a subset of M2E that focuses on integrating with Eclipse Web Tools Project so it is used in conjunction with JavaEE projects.
When I say "integrating", it really means that a lot of magic is happening behind the scenes to make everything work smoothly. One of those magic ingredients for m2e-wtp is that target/m2e-wtp-web-resources
folder, that is used when you're deploying your web-aplication inside Eclipse itself. Quoting from the 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.
So, fear not, the presence of that folder is actually an indication that everything is all right with your setup. If you delete that entry by mistake, it will be recreated the next time you update your Maven project in Eclipse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With