用捆绑的Tomcat创建一场战争

时间:2015-08-13 20:08:05

标签: maven tomcat maven-cargo

我的项目结构如下:

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

我希望dist模块将来自module1的war与一个Tomcat实例打包并将其全部压缩,以便我可以通过在服务器上解压缩来部署它。

我知道创建可运行的战争的插件和从jar开始的嵌入式tomcat但是我希望在webapps目录中使用我的战争将整个Tomcat压缩成拉链。

我可以使用程序集插件手动完成,但货物插件似乎应该按照我想要的方式进行。

我的观点看起来像这样:

<?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目录的存根包dir。

第三,也是最重要的一点,我的战争不在dist / target dir的任何地方!

1 个答案:

答案 0 :(得分: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>
相关问题