Maven webapp with Eclipse and WTP plugin deploy fi

2019-05-10 00:39发布

问题:

I use Eclipse J2EE 3.5 with Maven and tomcat. To deploy my maven webapp with WTP I added a Dynamic Web Module facet and changed the "org.eclipse.wst.common.component" file of the project because the webapp is not in a WebContent directory, here is the content of the file:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="toto">
<wb-resource deploy-path="/" source-path="/src/main/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"/>
<property name="context-root" value="toto"/>
<property name="java-output-path" value="/toto/target/classes"/>
</wb-module>
</project-modules>

But it never deploy the content correctly, in "workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\toto\" the directory structure is correct with WEB-INF and META-INF but empty, the jsp, html, css files are in "workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\toto\WEB-INF\classes\" with another WEB-INF and META-INF structure but with the files.

I don't understand this at all, thanks.

回答1:

You shouldn't mess with facets and Eclipse configuration files manually, these files should be derived from the Maven POMs. To do so, either use the maven-eclipse-plugin to generate Eclipse specific files from your Maven project or use the m2eclipse plugin to make Eclipse able to deal with Maven projects.

Both approaches provide Maven/Eclipse integration and support the WTP (i.e. allow to get your project recognized as a dynamic project than you can Run on a Server...), but are also different. The former is very light and only generates Eclipse files, the later provides full integration, wizards, etc but is heavier. I've been an happy user of both, using one or the othe really depends of what you're looking for.

Just in case, if you decide to install m2eclipse, make sure to install the optional Maven Integration for WTP component from the the m2eclipse Extras update site..