tags:

views:

1865

answers:

3

I have a Maven pom that uses <packaging>war</packaging>. But actually, I don't want build the war-file, I just want all the dependent jars collected and a full deployment directory created.

So I'm running the war:exploded goal to generate the deploy directory:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                      <webappDirectory>target/${env}/deploy</webappDirectory>
                      <archiveClasses>true</archiveClasses>
                    </configuration>
                    <goals>
                        <goal>
                            exploded
                        </goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

The trouble is, the war file still gets built. Is there a simple way of having <packaging>war</packaging> execute the war:exploded goal instead of the war:war goal?

Or is there another simple way to do this?

A: 

As far as I know (I'm still new to maven) this is not possible. The only default lifecycle you can skip is 'test'. In order to get to the deploy you have to package. You can read all about the default lifecycle order of execution here: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

Lisa
A: 

The only way I can think of to do what you want is to set use pom packaging (or create a custom packaging) and bind the required goals from the war packaging to the relevant phases of the lifecycle. If you go for pom packaging you can use define the war:war execution in a profile to allow you to package it, but you'll need to use the build-helper-maven-plugin attach-artifact goal to attach the war to the pom.

Note with this approach if you want to use any other war-specific processing it may cause you problems.

The lifecycle bindings for war packaging are listed in the Introduction to The Build Lifecycle (see the "Default Lifecycle Bindings - Packaging ejb / ejb3 / jar / par / rar / war" section).

To bind the relevant plugin executions to the pom packaging you would do as follows:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <executions>
        <execution>
          <id>process-resources</id>
          <phase>process-resources</phase>
          <goals>
            <goal>resources</goal
          </goal>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <artifactId>maven-compile-plugin</artifactId>
      <executions>
        <execution>
          <id>compile</id>
          <phase>compile</phase>
          <goals>
            <goal>compile</goal
          </goal>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <executions>
        <execution>
          <id>process-test-resources</id>
          <phase>process-test-resources</phase>
          <goals>
            <goal>testResources</goal
          </goal>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <executions>
        <execution>
          <id>test</id>
          <phase>test</phase>
          <goals>
            <goal>test</goal
          </goal>
        </execution>
      </executions>
    </plugin>
    <!-- package not wanted, install and deploy already defined for pom packaging-->
    <!--define war:war execution in a profile in case it is needed-->
Rich Seller
This is the correct approach.
bmargulies
+2  A: 

According builtin lifecycle bindings for war packaging in package phase war:war mojo is called.

You can call previous 'prepare-package' phase - all actions will be performed and after that call mojo war:exploded

mvn prepare-package war:exploded

The resuluts will be the same as yours but no war created.

cetnar
works for me as expected!
Gennady Shumakher
If you really like this, you can put the war:exploded invocation into the pom bound to the prepare-package phase. But you will have a problem if you ever need maven to go ahead and run the rest of the phases, so switching to <packaging>pom</packaging> is better.
bmargulies