如何避免maven启用WTP的项目自动生成web.xml



我已经用Maven, Eclipse, WTP设置了多模块环境。我安装的Eclipse插件有:

  • m2e的

  • m2e-extras

  • m2e-overlay

我有一个战争模块(w2),依赖于另一个战争模块(w1), w1有一个web.xml文件,而w2没有它自己的,它使用覆盖web.xml从w1。每当我单击maven ->更新项目配置时,eclipse都会自动为w2生成一个空的web.xml,这是我真的不想要的。

如何禁用此功能?

默认情况下,m2e-wtp特别要求WTP 不生成 Web .xml,如果不存在,则默认添加Dynamic Web Facet 2.5(或3.0,如果在类路径中检测到某些JavaEE 6依赖项)。WTP创建web.xml的唯一原因是如果我们要求安装一个facet版本<=2.4。但是这些方面只能从现有的web.xml中推断出来。看到讽刺了吗?

所以你看到的很可能是一个bug,你可能想创建一个bug报告,并附上一个示例项目到https://issues.sonatype.org/browse/MECLIPSEWTP

在此期间,你可以尝试使用m2wtp 0.14.0的开发构建,可从http://download.jboss.org/jbosstools/builds/staging/m2eclipse-wtp-e37/all/repo/,因为我最近在动态Facet版本变化的处理方式进行了更改。

至于第一个回复中描述的覆盖排除配置,这对你不起作用,因为你想专门使用w1的web.xml,而不是排除它。我宁愿颠倒叠加顺序,如:

<plugin>
  <groupId>org.apache.maven.plugins</groupId> 
  <artifactId>maven-war-plugin</artifactId> 
  <configuration>
    <overlays>
      <overlay>
        <groupId>foo.bar</groupId> 
        <artifactId>w1</artifactId> 
      </overlay>
      <overlay>
         <!-- this is the current w2, 
              it's resources will be overridden by w1
          -->
      </overlay>
    </overlays>
  </configuration>
</plugin>

您可以做的是-显式地排除依赖模块的web.xml,并且在打包时,它将从父war中选择xml:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <configuration>
        <overlays>
        <!--  Overlay w2 WAR with w1 specific web.xml --> 
          <overlay>
            <groupId>xyz</groupId> 
            <artifactId>w1</artifactId> 
            <excludes>
              <exclude>WEB-INF/web.xml</exclude> 
            </excludes>
          </overlay>
        </overlays>
      </configuration>
    </plugin>
  </plugins>
</build>

干杯!

最新更新