適切な統合テストを作成し、次の設定を使用してMavenビルド中に統合テストを行うことをお勧めします。
tomcatをダウンロードする場合、またはリポジトリのアーティファクトを使用する必要がある場合は、次の部分を使用できます。
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
<container>
<containerId>tomcat${tomcat.major}x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
<extractDir>${project.build.directory}/extract/</extractDir>
<downloadDir>${project.build.directory}/download/</downloadDir>
</zipUrlInstaller>
<output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
<log>${project.build.directory}/cargo.log</log>
</container>
<configuration>
<home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
<properties>
<cargo.logging>high</cargo.logging>
<cargo.servlet.port>9080</cargo.servlet.port>
<cargo.tomcat.ajp.port>9008</cargo.tomcat.ajp.port>
</properties>
</configuration>
</configuration>
次の部分は、指定されたtomcat(jettyと連携して動作するアプリケーション)を起動して展開するために使用されます。経由して最終的に開始したサーバーを停止する
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>mod-war</artifactId>
<type>war</type>
<pingURL>http://localhost:9080/mod-war</pingURL>
<pingTimeout>30000</pingTimeout>
<properties>
<context>mod-war</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</execution>
そしてもちろん:
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
最善のことは、アプリ-それ(と呼ばれるかもしれない別のMavenのモジュールにコンフィギュレーションなどのこの種を置くことですそれは統合テスト用です)。統合テストフェーズを実行し、上記のような構成を開始するライフサイクルを確認する一方、試験の 完全なサイクルは、単に
mvn verify
によって呼び出すことができます。しかし、統合テスト自体を実行するには、maven-failsafe-pluginを設定することが重要です。これについての詳細な説明は、あなたが何ができるかMaven Unit- and Integration Test Guide
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
は、なぜあなたは組み込みのTomcatで見ることができないhttp://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/startup/Embedded.html –
可能な複製[Tomcat 6を埋め込む方法](http://stackoverflow.com/questions/640022/howto-embed-tomcat-6) –
@ArunPJohny:これは私が探していたものでした。あなた(または誰かが)答えとしてそれを置くなら、私はそれを受け入れるでしょう:) –