4

私の目的は、戦争を別の戦争に含めることです。マイ プロジェクトの構造を参照してください。

+test-parent (Spring および Hibernate フレームワークのすべての一般的な依存関係がここにあります) -- test-core (すべての一般的なクラス type:jar のコレクション) -- test-web (個別の webapp として実行する必要がある webapp、test に依存) -core, type:war) -- test-web-2 (test-web,test-core, type:war に依存する webapp)

これを達成するためにmaven warプラグインを使用しました。

テストの親/pom.xml

<?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>test-parent</groupId>
    <artifactId>test-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>test-core</module>
        <module>test-web</module>
        <module>test-web-2</module>
    </modules>
    <dependencies>
        <!-- All common spring & hibernate dependencies -->
    </dependencies>
</project>

テストコア/pom.xml

<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>
    <groupId>test-parent</groupId>
    <artifactId>test-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>test-core</artifactId>
</project>

テスト web/pom.xml

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>test-parent</groupId>
    <artifactId>test-web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>test-web Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-core</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>test-web</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <packagingIncludes>**/*.xml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,**/*.jsp</packagingIncludes>
                    <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                    <attachClasses>true</attachClasses>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

test-web-2/pom.xml

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>test-parent</groupId>
    <artifactId>test-web-2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>test-web-2 Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-web</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-web</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <classifier>classes</classifier>
        </dependency>
    </dependencies>
    <build>
        <finalName>test-web-2</finalName>
    </build>
</project>

私の test-web-2 は test-web に依存しているので、すべてのクラス、リソースを test-web-2 にマージしたいと考えています。すべてのビルドを実行するmvn installと成功しますが、サーバーで test-web または test-web-2 を実行すると、WEB-INF の下に lib フォルダーがなく、親から必要なすべてのスプリング jar が含まれます。

両方のプロジェクトで異なるパッケージとjspファイル名を付けました。必要に応じて、適切なマージされたビルドを確認することさえできます。

親からのすべての依存jarを使用して、test-webおよびtest-web-2プロジェクトの両方で生成されたこのlibフォルダーを取得するにはどうすればよいですか?

4

2 に答える 2

3

プロジェクト構成を簡素化します。WARJava ソース コードを からに分離しJARます。この後、これを依存関係としてJAR別のものに追加するだけです。この場合、Java コードをマージするのは得策ではありません。WAR

リソースをマージするにはWAR、mavenオーバーレイを使用します。

サンプル溶液

* test-parent.pom
  * test-core (test-core.jar)         - shared code
  * test-web-parent (test-web-parent.pom)   - first project
    * core (test-web-core.jar)
    * web (test-web.war)
  * test-web-2-parent (test-web-2-parent.pom) - second project
    * core (test-web-2-core.jar)
    * web (test-web-2.war)

test-web.war依存関係があります:

  • test-web-core.jar
  • test-core.jar

test-web-2.war依存関係があります:

  • test-web-2-core.jar
  • test-core.jar

構成

test-parent.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>

    <groupId>test-parent</groupId>
    <artifactId>test-parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>test-core</module>
        <module>test-web-parent</module>
        <module>test-web-2-parent</module>
    </modules>

</project>

test-core.jar

<?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">
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-core</artifactId>

</project>

test-web-parent.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">
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-web-parent</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>core</module>
        <module>web</module>
    </modules>

</project>

test-web-core.jar

<?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">
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-web-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-web-core</artifactId>

    <dependencies>
        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

test-web.war

<?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">
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-web-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-web</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-web-core</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>jar</type>
        </dependency>
    </dependencies>

</project>

test-web-2-parent.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">
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-web-2-parent</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>core</module>
        <module>web</module>
    </modules>

</project>

test-web-2-core.jar

<?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">
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-web-2-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-web-2-core</artifactId>

    <dependencies>
        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

test-web-2.war

<?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">
    <parent>
        <groupId>test-parent</groupId>
        <artifactId>test-web-2-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-web-2</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-web-2-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!--first war-->
        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-web</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>runtime</scope>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>test-parent</groupId>
            <artifactId>test-web-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

ソースコード

于 2013-11-23T17:21:20.453 に答える