Eclipse: Change webapp folder in Maven pom.xml fil

2019-04-26 17:20发布

问题:

Is it possible to define a different location for the webapp folder than the standard one ("/src/main/webapp/") in pom.xml? I know that you can define your web folder with

<wb-resource deploy-path="/" source-path="/webapp"/>

in a file called "org.eclipse.wst.common.component". The problem is when I click Maven -> Update Project, this line is overwritten with the standard

<wb-resource deploy-path="/" source-path="/src/main/webapp"/>

And then I have problems testing my project with Tomcat7 within Eclipse. I'm very thankful for every hint.

回答1:

Answers in How to configure custom maven project structure are sufficient for a purely Maven build, i.e. from commandline. When import the project into Eclipse (via m2e), you need tell m2e a little bit more so that it can create and maintain the project structure properly within Eclipse.

Actually, from Eclipse's perspective, it doesn't really care about how your project folder structure looks like, as long as the webapp folder is declared as a source folder or inside a source folder, however, by modifying .classpath doesn't make much sense as it's a auto-generated file and changed quite often.

It is highly recommended to obey the convention if you are able to, if not, using the following configuration for your customization:

<build>
  <resources>
    <resource>
      <directory>${basedir}/webapp</directory>
    </resource>
    ... ...
  </resources>
  ... ...
</build>