如何使用Maven中的tomcat插件部署多次战争? [英] How can I deploy multiple wars using the tomcat plugin in maven?

查看:65
本文介绍了如何使用Maven中的tomcat插件部署多次战争?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

我无法对此进行测试,但是我可以想到两种方法.两种都可以为您工作.

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

选项1:

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

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>

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

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具有一些可用于避免绝对路径的属性.


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")

这篇关于如何使用Maven中的tomcat插件部署多次战争?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆