9

可能であれば、Tomcat の context.xml ファイルを WAR ファイルの META-INF ディレクトリから除外したいと考えています。これはMavenのカーゴプラグインで実行できますか? 正しい構成が見つからないようです。

4

3 に答える 3

17

ユーレカ!この問題を何日も研究した後、私はついに非常に効果的な解決策を見つけました。重要なのは、Tomcat XML コンテキスト フラグメント ファイルを取得し<configfiles>、 cargo の要素を使用して、それconf/Catalina/localhostを という名前のディレクトリにドロップすることcontext.xml.defaultです。唯一の欠点は、これによりコンテキスト定義がすべての Web アプリで利用できるようになることですが、Cargo がこの Tomcat インスタンスを使用しているだけで、他の Web アプリが存在しないため、これは問題ではありません。

構成は次のとおりです。

<configuration> <!-- Deployer configuration -->
    <type>standalone</type>
    <properties>
       <cargo.servlet.port>${tomcat6.port}</cargo.servlet.port>
    </properties>
    <deployables>
      <deployable>
        <groupId>com.myapp<groupId>
        <artifactId>myapp-war</artifactId>
        <type>war</type>
        <properties>
               <context>${tomcat6.context}</context>
        </properties>
       </deployable>
     </deployables>
    <configfiles>
       <configfile>
         <file>${basedir}/../config/tomcat-context.xml</file>
         <todir>conf/Catalina/localhost/</todir>
         <tofile>context.xml.default</tofile>
       </configfile>
    </configfiles>
</configuration>

最終的な結果として、テスト専用の偽の WAR モジュールはなくなり、WAR のマージもなくなります。これが誰かに役立つことを願っています。

于 2010-12-11T17:24:53.177 に答える
3

私はまだこれを行う方法を見つけていませんが、私のプロジェクトで機能する回避策を考え出しました。現在、基本的に 3 つのサブモジュールを含むプロジェクトがあります。

    dependencies
    webapp
    smoketest

「webapp」プロジェクトをビルドするときに、次のプラグイン宣言を実行します。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
        <id>create-war-smoketest</id>
        <phase>verify</phase>
        <goals>
            <goal>war</goal>
        </goals>
        <configuration>
            <webappDirectory>${project.build.directory}/exploded</webappDirectory>
            <primaryArtifact>false</primaryArtifact>
            <classifier>smoketest</classifier>
            <webResources>
            <resource>
                <filtering>true</filtering>
                <directory>src/test/resources/smoketest</directory>
                <targetPath>META-INF</targetPath>
                <includes>
                    <include>context.xml</include>
                </includes>
            </resource>
            </webResources>
        </configuration>
        </execution>
    </executions>
</plugin>

次に、SmokeTest プロジェクトで Cargo/WebTest スイートを実行しているときに、smoketest WAR ファイルを依存関係として指定し、Cargo 構成でデプロイ可能なものを次のように設定します。

<deployables>
    <deployable>
        <groupId>${pom.groupId}</groupId>
        <artifactId>webapp</artifactId>
        <type>war</type>
        <properties>
            <context>smoketest</context>
        </properties>
    </deployable>
</deployables>

依存関係は次のようになります。

<dependencies>
    <dependency>
        <groupId>${pom.groupId}</groupId>
        <artifactId>webapp</artifactId>
        <version>${pom.version}</version>
        <classifier>smoketest</classifier>
        <type>war</type>
        <scope>system</scope>
        <!-- trick the dependency plugin to never look for it in the repo -->
        <systemPath>${basedir}/../webapp/target/webapp-${pom.version}-smoketest.war</systemPath>
    </dependency>
</dependencies>

非常に汚れていますが、少なくとも機能します...今のところ。1 つの簡単なメモ: リポジトリ内のバージョンを検索しないように強制することに関する私のコメントは、現時点では間違っている可能性があります。このトリックは、ある時点での依存関係プラグインの変更によって壊れた可能性があると思います.

于 2010-11-29T23:54:03.860 に答える