簡體   English   中英

如何在maven中使用tomcat插件部署多個戰爭?

[英]How can I deploy multiple wars using the tomcat plugin in maven?

我有兩個戰爭,我使用tomcat插件在兩個maven項目中部署。 我想一步到位,並且能夠在一個maven項目中部署多個戰爭。 我怎樣才能做到這一點? 有什么建議?

我無法測試這個,但我能想到兩種方法。 要么適合你。

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

你可以創建一個“超級戰爭”並部署它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM