2

我试图让 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 文件?

4

2 回答 2

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.war并且artifact-0.1-with-other-junk.war都包含正确的文件。

于 2009-10-23T22:48:00.110 回答
0

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

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

<executions>
    <execution>
        <phase>package</phase>
        <goals>
          <goal>war</goal>
        </goals>
        <configuration>
        (...)
        </configuration>
    </execution>
</executions>
于 2009-10-16T15:10:16.780 回答