我可以制作一个Maven配置文件将webResources添加到战争中并仍添加非配置文件的webResources吗?

时间:2012-08-24 20:03:57

标签: maven maven-war-plugin

示例:

我希望并希望以下pom在“profile”配置文件处于活动状态时部署profileResources和commonResources,但它只部署profileResources。我该怎么做才能达到预期的效果?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>test</artifactId>
  <packaging>war</packaging>
  <version>0.0.0</version>
  <profiles>
    <profile>
      <id>profile</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
              <webResources>
                <resource>
                  <directory>src/main/profileResources</directory>
                </resource>
              </webResources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <webResources>
            <resource>
              <directory>src/main/commonResources</directory>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

工作版本(供将来参考)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>test</artifactId>
  <packaging>war</packaging>
  <version>0.0.0</version>
  <profiles>
    <profile>
      <id>profile</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
              <webResources>
                <resource>
                  <directory>src/main/profileResources</directory>
                </resource>
              </webResources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <webResources combine.children="append">
            <resource>
              <directory>src/main/commonResources</directory>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Git Word在破碎版和工作版之间的差异

diff --git a/tmp/broken-pom.xml b/tmp/working-pom.xml
index 2fd9bbf..b04683f 100644
--- a/tmp/broken-pom.xml
+++ b/tmp/working-pom.xml
@@ -31,5 +31,5 @@
        <version>2.1.1</version>
        <configuration>
          <webResources{+ combine.children="append"+}>
            <resource>
              <directory>src/main/commonResources</directory>

1 个答案:

答案 0 :(得分:9)

尝试将combine.children="append"添加到非配置文件插件中的resources元素中 - 我认为它正在搞乱,因为默认行为意味着配置文件设置将覆盖在树上方具有相同名称的任何内容。有关合并/追加属性的详细信息,请参阅http://maven.apache.org/pom.html#Plugins