如何为 maven war 插件配置多个输出目录?

2 java maven

我已经配置了以下 Maven 战争插件,但我只创建了一个输出目录:

     <plugin>
         <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>              
             <configuration> 
                <outputDirectory>C:\EclipseWorkspace\my_path\myPath2</outputDirectory>
              </configuration>
            <executions>
              <execution>
                <id>default-war</id>
                <phase>package</phase>
                <goals>
                  <goal>war</goal>
                </goals>
              </execution>
            </executions>
      </plugin>
Run Code Online (Sandbox Code Playgroud)

例如,如何配置此 pligin 以创建两个输出目录?

Edw*_*uck 5

首先,我强烈建议您不要将输出目录覆盖为“target/...”以外的其他内容。Maven 遵循约定,虽然您可以在远离约定的情况下配置它,但这确实意味着您必须在远离传统位置的地方配置所有内容

现在,如果您想复制工作,只需添加第二个执行。为此,您将需要两个不同的执行 ID。

        <executions>
          <execution>
            <id>default-war</id>
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
          </execution>
          <execution>
            <id>additional-war</id>
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
          </execution>
        </executions>
Run Code Online (Sandbox Code Playgroud)

并且要让它们具有不同的配置,请在执行中添加本地配置差异。

       <executions>
          <execution>
            <id>default-war</id>
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
            <configuration>
              ... stuff specific to the first war ...
            </configuration>
          </execution>
          <execution>
            <id>additional-war</id>
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
            <configuration>
              ... stuff specific to the second war ...
            </configuration>
          </execution>
        </executions>
Run Code Online (Sandbox Code Playgroud)

请注意,这不会真正为单个 war 文件创建两个输出目录,而是会将 war 两次重新打包到两个不同的输出目录。这是一个很好的细节,但有时它可能很重要。