2009-07-27 154 views

回答

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元素)。然後,您可以定義一個第三個項目,其中包含引用每個戰爭項目的模塊聲明。當父母建成的時候,兩個戰爭將會建成並且部署戰爭。

模塊聲明的第三個項目:

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

哎,非常感謝你的建議。 我有一個後續問題。在pom中,而不是給戰爭文件提供絕對路徑,有沒有辦法可以從本地存儲庫或遠程存儲庫路徑中獲取war文件。 – nagl 2009-07-28 02:49:07

0

您可以創建一個「超級戰爭」和部署,以及