在<execution>标记</execution>中运行时,Maven WAR插件不读取配置

时间:2009-10-16 13:51:02

标签: maven-2 war

我正在尝试让Maven使用WAR插件执行多次执行。只要按以下方式定义它就可以正常工作:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
<version>1.0</version>
    <configuration>
    (...)
    </configuration>

但不是以下列方式

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
            (...)
            </configuration>
        </execution>
    </executions>
</plugin>

Maven无法找到我在<configuration>标记中定义的任何资源。我是否遗漏了任何重要内容,和/或是否有更好的方法在单个构建中构建多个WAR文件?

2 个答案:

答案 0 :(得分:1)

我没有看到如何关闭默认生成的战争,但你可以在<executions>元素之外使用一个配置,其余部分在内部:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1-beta-1</version>
    <configuration>
      <classifier>with-junk</classifier>
      <!-- temp directory that the webapp is assembled in (each must be different) -->
      <webappDirectory>${project.build.directory}/build-with-junk</webappDirectory>
      <webResources>
        <resource>
          <directory>junk</directory>
          <includes>
            <include>**/*</include>
          </includes>
        </resource>
      </webResources>
    </configuration>
    <executions>
      <execution>
        <id>add-other-junk</id>
        <phase>package</phase>
        <goals>
          <goal>war</goal>
        </goals>
        <!-- exclude prior configuration -->
        <inherited>false</inherited>
        <configuration>
          <classifier>with-other-junk</classifier>
          <webappDirectory>${project.build.directory}/build-other-junk</webappDirectory>
          <webResources>
            <resource>
              <directory>other-junk</directory>
              <includes>
                <include>**/*</include>
              </includes>
            </resource>
          </webResources>
        </configuration>
      </execution>
    </executions>
  </plugin>

对我来说,这会构建artifact-0.1-with-junk.warartifact-0.1-with-other-junk.war并且都包含正确的文件。

答案 1 :(得分:0)

第二个版本仅将配置应用于您指定的阶段。我现在无法确认这一点,但我猜它没有被应用,因为您没有指定要应用的配置目标。

如果将war目标定义添加到执行中,它是否会被应用?像这样:

<executions>
    <execution>
        <phase>package</phase>
        <goals>
          <goal>war</goal>
        </goals>
        <configuration>
        (...)
        </configuration>
    </execution>
</executions>