3

Webプロジェクトとそれをデプロイできるいくつかの環境があると仮定しましょう。そして、Mavenに一度に複数のアーティファクトをビルドしてもらいたい(たとえば、dev a prodの場合)。A-warモジュールとA-earモジュール(A-warを含む)があります。各戦争アーティファクトには、その環境にのみ関連する情報が含まれている可能性があります。

まず、A-warモジュール用にpom.xmlファイルを構成しました。

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <executions>
                    <execution>
                        <id>package-prod</id>
                        <phase>package</phase>
                        <configuration>
                            <classifier>prod</classifier>
                            <webappDirectory>${project.build.directory}/${project.build.finalName}-prod</webappDirectory>
                            <webResources>
                                <resource>
                                    <directory>src/env/prod</directory>
                                </resource>
                            </webResources>
                        </configuration>
                        <goals>
                            <goal>war</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>package-dev</id>
                        <phase>package</phase>
                        <configuration>
                            <classifier>dev</classifier>
                            <webappDirectory>${project.build.directory}/${project.build.finalName}-dev</webappDirectory>
                            <webResources>
                                <resource>
                                    <directory>src/env/dev</directory>
                                </resource>
                            </webResources>
                        </configuration>
                        <goals>
                            <goal>war</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
    <finalName>A-war</finalName>
</build>

これは正常に機能します-2* war *は、ターゲットフォルダーA-war-prodおよびA-war-devに作成されます。

今、私はこれらの戦争のそれぞれのために耳のアーティファクトを構築したいと思います。

A-earモジュールのpom.xmlの主な内容は次のとおりです。

<dependencies>
    <dependency>
        <groupId>gr.id</groupId>
        <artifactId>A-war</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <classifier>prod</classifier>
        <scope>provided</scope>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>gr.id</groupId>
        <artifactId>A-war</artifactId>
        <classifier>dev</classifier>
        <version>0.0.1-SNAPSHOT</version>
        <scope>provided</scope>
        <type>war</type>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <executions>
                <execution>
                    <id>package-dev</id>
                    <phase>package</phase>
                    <configuration>
                        <classifier>dev</classifier>
                        <version>5</version>
                        <modules>
                            <webModule>
                                <groupId>gr.id</groupId>
                                <artifactId>A-war</artifactId>
                                <classifier>dev</classifier>
                                <contextRoot>/A-war</contextRoot>
                                <bundleFileName>/A-war.war</bundleFileName>
                            </webModule>
                        </modules>
                    </configuration>
                    <goals>
                        <goal>ear</goal>
                    </goals>
                </execution>
                <execution>
                    <id>package-prod</id>
                    <phase>package</phase>
                    <configuration>
                        <classifier>prod</classifier>
                        <version>5</version>
                        <modules>
                            <webModule>
                                <groupId>gr.id</groupId>
                                <artifactId>A-war</artifactId>
                                <classifier>prod</classifier>
                                <contextRoot>/A-war</contextRoot>
                                <bundleFileName>/A-war.war</bundleFileName>
                            </webModule>
                        </modules>
                    </configuration>
                    <goals>
                        <goal>ear</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <finalName>A-ear</finalName>
</build>

また、A-ear-dev.earとA-ear-prod.earの2つの耳**を作成します。そして、これらの**のそれぞれには、A-war.warアーティファクトが含まれています。そして、1つの小さな詳細を除いてすべてがうまくいくでしょう:これらの**warファイルは同じです。つまり、A-ear-dev.earにはA-war-dev.war(A-war.warに名前が変更されています)が含まれていますが、A-ear-prod.earには独自のA-war-dev.warではなく同じA-war-dev.warが含まれていますA-war-prod.war。さらに、実行の順序を変更した場合(devよりも高いprodの作成を移動)、これらの* ear *には両方ともA-war-prod.warが含まれていました。

Mavenの出力からわかるように、ear **の構築を開始すると、最初の戦争が最初の** earのフォルダーにコピーされますが、2番目の場合はコピーされません。

[INFO] --- maven-ear-plugin:2.8:ear (package-dev) @ A-ear
---
[INFO] Copying artifact [war:gr.id:A-war:dev:0.0.1-SNAPSHOT] to [/A-war.war]
[INFO] Including custom manifest ....
[INFO] Copy ear sources to ...

[INFO] Building jar: <location>\A-ear\target\A-ear-dev.ear

....
[INFO] --- maven-ear-plugin:2.8:ear (package-prod) @ A-ear ---
[INFO] Copy ear sources to ...
[INFO] Including custom manifest file ...

[INFO] Building jar: <location>\A-ear\target\A-ear-prod.ear

それで、多分誰かが毎回mavenコピーwarファイルを強制する方法についての考えを持っていますか?

4

1 に答える 1

5

私が知ったように、Mavenがwarファイルをtempディレクトリにコピーしているとき、それは書き換えられません-同じ名前のファイルがある場合、それは置き換えられません。したがって、最初のアーティファクトのコピー後、実行モジュールでポイントされている最初のアーティファクトが常にコピーされます。他のすべてのアーティファクトはコピーされませんでした。したがって、このアーティファクトはすべての結果のに配置されました。

したがって、この問題の解決策は、次のように、実行タグごとに作業ディレクトリを指定することです。

            <execution>
                <id>package-prod</id>
                <phase>package</phase>
                <configuration>
                    <workDirectory>target/prod</workDirectory>
                    <classifier>prod</classifier>
                    <version>5</version>
                    <modules>
                        <webModule>
                            <groupId>gr.id</groupId>
                            <artifactId>A-war</artifactId>
                            <classifier>prod</classifier>
                            <contextRoot>/A-war</contextRoot>
                            <bundleFileName>/A-war.war</bundleFileName>
                        </webModule>
                    </modules>
                </configuration>
                <goals>
                    <goal>ear</goal>
                </goals>
            </execution>
于 2013-03-27T23:44:07.093 に答える