【问题标题】:Conditional inclusion of files in maven在 Maven 中条件包含文件
【发布时间】:2013-07-02 16:26:48
【问题描述】:

我有一个 JEE6 web 应用程序项目。项目结构符合 maven 约定。

现在我已经为这个项目引入了额外的 web.xml 文件。

所以它们现在存储在 WEB-INF 中,如下所示:

WEB-INF/

     |__ A/web.xml

     |__ B/web.xml

根据属性构建包含正确 xml 的战争的 maven 方法是什么。

我知道如何在 maven 中添加自定义属性。但是我找不到如何配置 maven 插件,以便在构建 war 文件时选择合适的文件。

欢迎在这种情况下提供任何提示/建议/maven 最佳实践。

谢谢!!

【问题讨论】:

    标签: java build maven-3 java-ee-6


    【解决方案1】:

    maven war plugin 可以配置为添加和过滤一些外部资源。见http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

    所以我会用 2 个这样的 war 插件配置制作 2 个 maven profiles

       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <webResources>
            <resource>
              <!-- this is relative to the pom.xml directory -->
              <directory>src/main/webapp/WEB-INF/__A</directory>
              <includes>
                <include>web.xml</include>
              </includes>
              <targetPath>WEB-INF</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>
      <!-- repeat for your second profile -->
    

    但我认为更好的解决方案(如果您的项目允许的话)是只保留一个 web.xml 文件,其中包含一些过滤属性。在这种情况下,您只需配置您的 war 插件以启用一些过滤,如下所示:

    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
        </configuration>
      </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-12
      • 2017-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 2019-12-04
      • 2016-12-14
      相关资源
      最近更新 更多