tags:

views:

629

answers:

2

I have two wars which I deploy in two maven projects using tomcat plugin. I want to do this in one step and be able to deploy more than one war in a single maven project. How can I do this? any suggestions?

+1  A: 

I'm not in a position to test this, but there are two approaches I can think of. Either may work for you.

Option 1:

In one of the projects you can define the configuration for the tomcat plugin. In the snippet below there are two executions defined, both bound to the pre-integration-test phase (this might not be the best phase to do this, but it seems a good starting point as the war will have been packaged). Each execution will deploy the war defined in its configuration's warFile property.

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <version>1.0-beta-1</version>
        <executions>
          <execution>
            <id>deploy1</id>
            <phase>pre-integration-test</phase>
            <configuration>
              <warFile>path/to/my/warFile1.war</warFile>
            </configuration>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
          <execution>
            <id>deploy2</id>
            <phase>pre-integration-test</phase>
            <configuration>
              <warFile>path/to/my/warFile2.war</warFile>
            </configuration>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

Option 2: This is probably the better approach. Define one execution in each war (you can omit the warFile element as the default can be used). You can then define a third project with a modules declaration referencing each war project. When the parent is built both wars will be be built and the wars deployed.

The modules declaration for the third project:

<modules>
  <module>relative/path/to/war1</module>
  <module>relative/path/to/war2</module>
<modules>

And the config for each war project:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <version>1.0-beta-1</version>
        <executions>
          <execution>
            <id>deploy</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>


Maven has some properties you can use to avoid absolute paths.

${maven.repo.local} will resolve to the local repository
${project.basedir} is the project directory (the root of the project)
${project.build.directory} is the build directory (default is "target")
${project.build.outputDirectory} is the directory where compilation output goes (default is "target/classes")
Rich Seller
hey, thank you very much for your suggestion. I had a followup question. in the pom instead of giving absolute path to the war file is there a way that the war file can be picked up from the local repository or remote repository path.
nagl
I've added some properties to the answer, you can specify a relative path by using ${property}/path/to/reference
Rich Seller
A: 

you can create a "super war" and deploy that, as well

rogerdpack