我有两场战争,我使用tomcat插件在两个maven项目中部署。 我想一步到位,并且能够在一个maven项目中部署多个战争。 我怎样才能做到这一点?有什么建议吗?
答案 0 :(得分: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>
选项2: 这可能是更好的方法。在每次战争中定义一个执行(您可以省略warFile元素,因为可以使用默认值)。然后,您可以使用引用每个war项目的模块声明来定义第三个项目。建立父母时,将建立战争并部署战争。
第三个项目的模块声明:
<modules>
<module>relative/path/to/war1</module>
<module>relative/path/to/war2</module>
<modules>
每个战争项目的配置:
<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.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")
答案 1 :(得分:0)
你可以创建一个“超级战争”并部署它,