如何在maven中使用tomcat插件部署多个战争?

nag*_*agl 8 tomcat maven-2

我有两个战争,我使用tomcat插件在两个maven项目中部署.我想一步到位,并且能够在一个maven项目中部署多个战争.我怎样才能做到这一点?有什么建议?

Ric*_*ler 6

我无法测试这个,但我能想到两种方法.要么适合你.

选项1:

在其中一个项目中,您可以定义tomcat插件的配置.在下面的片段中,定义了两个执行,都绑定到预集成测试阶段(这可能不是执行此操作的最佳阶段,但它似乎是一个很好的起点,因为战争将被打包).每次执行都将部署在其配置的warFile属性中定义的war.

<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>
Run Code Online (Sandbox Code Playgroud)

选项2: 这可能是更好的方法.在每次战争中定义一个执行(您可以省略warFile元素,因为可以使用默认值).然后,您可以使用引用每个war项目的模块声明来定义第三个项目.在构建父级时,将构建两个战争并部署战争.

第三个项目的模块声明:

<modules>
  <module>relative/path/to/war1</module>
  <module>relative/path/to/war2</module>
<modules>
Run Code Online (Sandbox Code Playgroud)

每个战争项目的配置:

<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>
Run Code Online (Sandbox Code Playgroud)

Maven有一些属性可以用来避免绝对路径.

${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")
Run Code Online (Sandbox Code Playgroud)