每次启动环境时,Eclipse都会覆盖我的web.xml

时间:2013-03-27 11:17:03

标签: eclipse maven tomcat

我在Windows 7平台上运行带有Tomcat 7的Eclipse Juno。

当我使用Maven构建项目时,web.xml被正确派生。我进入eclipse并刷新并检查我的target \ web.xml,到目前为止一切都很好。我运行Tomcat服务器,一切正常。

一旦我重新启动Eclipse,web.xml就会回到占位符版本,我必须再次从Maven构建并在运行Tomcat之前刷新源代码。

我在Ubuntu上设置完全一样,但这不会发生。

在Project Facets下,我正在使用Dynamic Web Module 3.0。

=======

<artifactId>nordicedge</artifactId>
  <packaging>war</packaging>
  <name>${project.artifactId}</name>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>kivadmin2_logic</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>kivUpdater</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.directwebremoting</groupId>
      <artifactId>dwr</artifactId>
      <version>3.0.M1</version>
    </dependency>
     <dependency>
      <groupId>rome</groupId>
      <artifactId>rome</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>se.nordicedge</groupId>
        <artifactId>neim</artifactId>
        <version>4.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>se.nordicedge</groupId>
        <artifactId>neutil</artifactId>
        <version>4.2</version>
        <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>     
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
          <configuration>
            <webXml>${project.build.directory}/web.xml</webXml>
            <warSourceExcludes>**/DSEditor.properties,**/META-INF/context.xml</warSourceExcludes>
          </configuration>
      </plugin>      
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4</version>
      </plugin>
    </plugins> 
    <resources>
      <resource>
        <directory>${basedir}/src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
        <includes>
          <include>web.xml</include>
        </includes>
        <filtering>true</filtering>
        <targetPath>${project.build.directory}</targetPath>
      </resource>
      <resource>
        <directory>${basedir}/src/main/webapp/WEB-INF/NEIDMgmt</directory>
        <includes>
          <include>DSEditor.properties</include>
        </includes>
        <filtering>true</filtering>
        <targetPath>${project.build.directory}/nordicedge/WEB-INF/NEIDMgmt</targetPath>
      </resource>
      <resource>
        <directory>${basedir}/src/main/webapp/META-INF</directory>
        <includes>
          <include>context.xml</include>
        </includes>
        <filtering>true</filtering>
        <targetPath>${project.build.directory}/nordicedge/META-INF</targetPath>
      </resource>
    </resources>    
  </build>

1 个答案:

答案 0 :(得分:1)

如果你使用 m2e-wtp ,首先检查你是否是最新版本,意味着0.17。之后,对于资源过滤,使用Maven War plugin以便在标准构建阶段过滤它们:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/webapp</directory>
                <includes>
                    <include>**/*.xhtml</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
                <targetPath>WEB-INF/classes</targetPath>
            </resource>
        </webResources>
    </configuration>
</plugin>