【问题标题】:Web.xml is not getting included in War using mvn pluginWeb.xml 没有使用 maven 插件包含在 War 中
【发布时间】:2015-04-30 06:44:50
【问题描述】:

我正在尝试将 web.xml 包含在战争中。

这是我的pom.xml 的样子,我已将maven-resources-pluginmaven-war-plugin 添加到pom 中

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.5</version>
  <executions>
    <execution>
      <id>copy-web.xml</id>
      <phase>process-resources</phase>
      <goals>
        <goal>copy-resources</goal>
      </goals>
      <configuration>
        <outputDirectory>${basedir}/war/WEB-INF</outputDirectory>
        <resources>
          <resource>
            <directory>src/main/webapp/WEB-INF/</directory>
            <filtering>true</filtering>
            <includes>
              <include>web.xml</include>
            </includes>
          </resource>
        </resources>
      </configuration>
    </execution>
  </executions>
</plugin>

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <webXml>${basedir}/war/WEB-INF/web.xml</webXml>
  </configuration>
</plugin>

<plugin>
  <artifactId>maven-clean-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <filesets>
      <fileset>
        <directory>tomcat</directory>
      </fileset>
      <fileset>
        <directory>war/WEB-INF/classes</directory>
      </fileset>
      <fileset>
        <directory>war/WEB-INF/lib</directory>
      </fileset>
    </filesets>
  </configuration>
</plugin>

但是当我在这里提取战争时,我得到的就是这里

/tomcat/work/Catalina/localhost/XProject/WEB-INF
/tomcat/work/Catalina/localhost/XProject/WEB-INF/classes
/tomcat/work/Catalina/localhost/XProject/WEB-INF/lib

我做错了什么?

【问题讨论】:

  • 能否分享整个 pom.xml
  • 为什么需要过滤web.xml?
  • @SaurabhJhunjhunwala - 这或多或少是我在 pom 中所拥有的,在这方面很有用,其余的 pom 包括依赖项和其他插件。
  • @khmarbaise - 没有具体用途,我只是在尝试一些更改。
  • 你是否在 pom.xml 中添加了 war

标签: java maven plugins dependency-management


【解决方案1】:

我已经多次使用 maven-war-plugin。这是代码sn-p。如果 web.xml 存在于您的文件夹结构中,这将包括 web.xml,否则忽略。

我认为您的代码 sn-p 的问题可能与 web.xml 的相对路径有关。使用以下 maven-war-plugin 解决您的问题

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>

【讨论】:

  • 仍然没有运气。
  • 你检查过 web.xml 的相对路径吗?并从你的 pom.xml 中删除 maven-resources-plugin
【解决方案2】:

添加 warsourcedirectory 标记。

    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <warSourceDirectory>WebContent</warSourceDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

【讨论】:

    【解决方案3】:

    我在将 web.xml 放在默认路径中时遇到了同样的问题

    src/main/webapp/WEB-INF/web.xml
    

    但未包含在 .war 中。

    根据@sitakant 的建议,我从 pom.xml 中删除了 maven-resources-plugin,并且 web.xml 现在包含在 .war 中,无需进一步配置。

    【讨论】:

      猜你喜欢
      • 2016-09-20
      • 1970-01-01
      • 2014-10-07
      • 2013-11-17
      • 2014-08-20
      • 1970-01-01
      • 2014-11-12
      • 2020-01-24
      • 2011-09-29
      相关资源
      最近更新 更多