2015-08-13 82 views
0

我的項目結構如下:創建WAR捆綁的Tomcat

+Parent 
| 
+---dist 
| 
+---module1 (war) 
| 
+---module2 (jar) 

我想DIST模塊和Tomcat實例套餐模塊1戰和zip這一切,這樣我可以部署通過在服務器上解壓縮。

我知道有關創建可運行的戰爭和嵌入式tomcat的插件,這些插件是從一個jar開始的,但我希望整個Tomcat與我在webapps目錄中的戰爭拉鍊在一起。

我可能會用程序集插件手動執行它,但貨物插件看起來應該按照我想要的做。

我DIST POM看起來是這樣的:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <artifactId>my-parent</artifactId> 
    <groupId>com.my.package</groupId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>dist</artifactId> 
    <packaging>pom</packaging> 

    <dependencies> 
    <dependency> 
     <groupId>${project.parent.groupId}</groupId> 
     <artifactId>my-war</artifactId> 
     <version>${project.parent.version}</version> 
     <type>war</type> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.codehaus.cargo</groupId> 
     <artifactId>cargo-maven2-plugin</artifactId> 
     <version>1.4.15</version> 
     <configuration> 
      <container> 
      <!--containerId must be equal to one of the containers supported by Cargo --> 
      <!--https://codehaus-cargo.github.io/cargo/Container.html--> 
      <containerId>tomcat8x</containerId> 
      <artifactInstaller> 
      <groupId>org.apache.tomcat</groupId> 
      <artifactId>tomcat</artifactId> 
      <version>8.0.24</version> 
      </artifactInstaller> 
      </container> 
      <configuration> 
      <type>standalone</type> 
      <home>${basedir}/target/cargo/installs/tomcat-8.0.24</home> 
      </configuration> 
      <deployables> 
      <deployable> 
       <groupId>${project.parent.groupId}</groupId> 
       <artifactId>my-war</artifactId> 
       <type>war</type> 
      </deployable> 
      </deployables> 
     </configuration> 
     <executions> 
      <execution> 
      <id>package</id> 
      <phase>package</phase> 
      <goals> 
       <goal>package</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

首先,它似乎很奇怪,我要指定當我使用神器安裝程序的主目錄。

二,輸出結構是這樣的:

+---dist 
| \---target 
|  +---cargo 
|  | \---installs 
|  |  \---tomcat-8.0.24 
|  |   \---apache-tomcat-8.0.24 
|  |    +---bin 
|  |    +---conf 
|  |  .......... 
|  |  .......... 
|  |    
|  \---package 
|   +---apache-tomcat-8.0.24 
|   | +---bin 
|   | +---conf 
|   | .......... 
|   | .......... 
|   +---bin 
|   +---lib 
|   \---temp 

注意如何tomcat的目錄是包的子目錄,但已經有tomcat的目錄包目錄的存根。

第三也是最重要的是,我的戰爭並不在dist/target目錄中的任何地方!

回答

0

我不確定額外的目錄是從哪裏來的,但現在已經解決了。 我想我可能是從dist模塊運行包而不是根模塊,這就是爲什麼戰爭不在那裏。

下面的示例爲我工作,然後我添加maven程序集插件來壓縮它。

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.stackoverflow</groupId> 
    <artifactId>question</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <properties> 
    <tomcat.version>8.0.24</tomcat.version> 
    </properties> 

    <build> 
    <plugins> 
     <!--Create a war--> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>2.6</version> 
     <!--This is an empty demo project--> 
     <configuration> 
      <failOnMissingWebXml>false</failOnMissingWebXml> 
     </configuration> 
     </plugin> 
     <!--Create the Tomcat bundle with our war in it--> 
     <plugin> 
     <groupId>org.codehaus.cargo</groupId> 
     <artifactId>cargo-maven2-plugin</artifactId> 
     <version>1.4.15</version> 
     <configuration> 
      <container> 
      <!--containerId must be equal to one of the containers supported by Cargo --> 
      <!--https://codehaus-cargo.github.io/cargo/Container.html--> 
      <containerId>tomcat8x</containerId> 
      <artifactInstaller> 
       <groupId>org.apache.tomcat</groupId> 
       <artifactId>tomcat</artifactId> 
       <version>${tomcat.version}</version> 
      </artifactInstaller> 
      </container> 
      <configuration> 
      <type>standalone</type> 
      <home>${project.build.directory}/cargo/installs/tomcat-${tomcat.version}/apache-tomcat-${tomcat.version} 
      </home> 
      </configuration> 
      <deployables> 
      <deployable> 
       <groupId>${project.groupId}</groupId> 
       <artifactId>${project.artifactId}</artifactId> 
       <type>war</type> 
      </deployable> 
      </deployables> 
     </configuration> 
     <executions> 
      <execution> 
      <id>cargo-deploy</id> 
      <phase>package</phase> 
      <goals> 
       <goal>deploy</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
</project>