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

发布于 2024-12-01 19:14:06 字数 367 浏览 0 评论 0原文

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

  • m2e

  • m2e-extras

  • m2e-overlay

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

我怎样才能禁用这个功能?

I have setup multi-modules environment with Maven, Eclipse, WTP.
The Eclipse Plugins I installed are:

  • m2e

  • m2e-extras

  • m2e-overlay

I have a war module(w2) that depends on another war module(w1), w1 has a web.xml file, and w2 doesn't have it's own, it uses overlay web.xml from w1. Whenever I click maven -> Update project configuration, eclipse automatically generates an empty web.xml for w2 which I really don't want.

How can I disable this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倒带 2024-12-08 19:14:06

默认情况下,m2e-wtp 特别要求 WTP 如果不存在 web.xml,则不生成该文件,并默认添加 Dynamic Web Facet 2.5(如果在类路径中检测到某些 JavaEE 6 依赖项,则添加 3.0)。
WTP 创建 web.xml 的唯一原因是如果我们要求安装 Facet 版本 <=2.4。但这些方面只能从现有的 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>

By default, m2e-wtp specifically asks WTP to not generate a web.xml if none exists and adds the Dynamic Web Facet 2.5 by default (or 3.0 if some JavaEE 6 dependencies are detected in the classpath).
The only reason WTP would create the web.xml would be if we asked to install a facet version <=2.4. But these facets can only be inferred from an existing web.xml. See the irony?

So what you see is most likely a bug and you might want to create a bug report with a sample project attached to https://issues.sonatype.org/browse/MECLIPSEWTP

In the mean time you can try to use a dev build of m2e-wtp 0.14.0, available from http://download.jboss.org/jbosstools/builds/staging/m2eclipse-wtp-e37/all/repo/, as I recently made changes in the way Dynamic Facet version changes are handled.

And as for the overlay exclusion configuration described in the first reply, that wouldn't work for you since you want to specifically use w1's web.xml, not exclude it. I would rather invert the overlay order like :

<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>
毁虫ゝ 2024-12-08 19:14:06

您可以做的是 - 显式排除依赖模块的 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>

干杯!

What you can do is - explicitly exclude the dependent module's web.xml and while packaging, it will pick the xml from the parent war:

<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>

Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文