【问题标题】:How to avoid maven WTP enabled project automatically generates web.xml?如何避免启用maven WTP的项目自动生成web.xml?
【发布时间】:2011-11-06 11:45:37
【问题描述】:

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

  • m2e

  • m2e-extras

  • m2e-overlay

我有一个依赖于另一个战争模块(w1) 的战争模块(w2),w1 有一个web.xml 文件,而w2 没有它自己的,它使用来自w1 的覆盖web.xml。每当我单击 maven -> Update project configuration 时,eclipse 会自动为 w2 生成一个我真的不想要的空 web.xml。

如何禁用此功能?

【问题讨论】:

    标签: eclipse maven maven-2 eclipse-wtp


    【解决方案1】:

    默认情况下,m2e-wtp 特别要求 WTP不生成 web.xml 如果不存在,并默认添加 Dynamic Web Facet 2.5(如果在类路径)。 WTP 创建 web.xml 的唯一原因是我们要求安装一个

    因此,您看到的很可能是一个错误,您可能希望创建一个错误报告,并附上一个示例项目到https://issues.sonatype.org/browse/MECLIPSEWTP

    与此同时,您可以尝试使用 m2e-wtp 0.14.0 的开发版本,可从http://download.jboss.org/jbosstools/builds/staging/m2eclipse-wtp-e37/all/repo/ 获得,因为我最近对处理 Dynamic 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>
    

    【讨论】:

      【解决方案2】:

      您可以做的是 - 明确排除依赖模块的 web.xml 并在打包时从父战争中选择 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>
      

      干杯!

      【讨论】:

        猜你喜欢
        • 2015-03-04
        • 1970-01-01
        • 1970-01-01
        • 2011-03-18
        • 1970-01-01
        • 2010-10-29
        • 1970-01-01
        • 2016-08-22
        • 1970-01-01
        相关资源
        最近更新 更多