1

私はMavenプロジェクトを持っており、Web、Persistence、Common、Otherの4つのコンポーネントがあります。

私のPOMファイルからの関連するもの:

親POM:

<groupId>com.test</groupId>
<artifactId>test</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<modules>
    <module>components/TestWeb</module>
    <module>components/TestOther</module>
    <module>components/TestPersistence</module>
    <module>components/TestCommon</module>
</modules>


<build>
    <defaultGoal>package</defaultGoal>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <dependentWarExcludes>
                    **/hibernate.cfg.xml,**/sql-map-config.xml,**/web.xml,WEB-INF/classes/META-INF/**
                </dependentWarExcludes>
            </configuration>
        </plugin>
     </plugins>
 </build>

一般的なpom:

<modelVersion>4.0.0</modelVersion>
<artifactId>test-common</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>

永続性pom:

<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-persistence</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>


<dependencies>
  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>

ウェブpom:

<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-web</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>TestWeb</name>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>

  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>


  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-persistence</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>


  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-other</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>

コピー&ペーストで何かが壊れたのかもしれませんが、XMLは有効です。

  • mvn packageを実行すると、プロジェクトのWARファイルは作成されませんが、すべてのコンポーネントパッケージが作成され、整形式になっています。
  • 次に実行するmvn war:warと、WARファイルは空で生成されます。

どうすればこれを修正できますか?

4

2 に答える 2

1

ルートプロジェクトにプラグインがあると機能しません。このように、ここでプラグインを構成できます

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

ただし、アクティブにするには、サブプロジェクトで参照する必要があります(maven-compiler-pluginやmaven-resource-pluginなどのデフォルトプロセスの一部であるプラグインを除く)。

したがって、war-plugin構成をpluginManagementルートプロジェクトに移動して、

<build>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1</version>
        <execution>
            <goals>...</goals>
        </execution>
    </plugin>
</build>

戦争プロジェクトで、または構成全体を戦争に移動します。

追記:ルートpom内のモジュールの順序が、プロジェクト間の依存関係に一致していることを確認してください(この場合は、順序を逆にしてください)。

于 2010-10-08T19:20:03.640 に答える
1

同様のプロジェクト構造を作成し、提供したPOMを貼り付けましたが、問題を再現できませんでした。mvn package集約pomからの実行は、期待どおりに機能します。

$mvnパッケージ
[情報]プロジェクトをスキャンしています...
..。
[情報]  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - - -------------------------
[情報]リアクターの概要:
[情報]  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - - -------------------------
[情報]名前なし-com.test:test:pom:0.0.1-SNAPSHOT............成功[5.819s]
[情報]名前なし--com.test:test-common:jar:0.0.1-SNAPSHOT ..... SUCCESS [3.343s]
[情報]名前なし-com.test:test-persistence:jar:0.0.1-SNAPSHOT SUCCESS [0.136s]
[情報]名前なし--com.test:test-other:jar:0.0.1-SNAPSHOT ...... SUCCESS [0.079s]
[情報]名前なし-com.test:test-web:war:0.0.1-SNAPSHOT........成功[1.899s]
[情報]  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - - -------------------------
[情報]  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - - -------------------------
[情報]成功を収める
[情報]  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - - -------------------------
..。

そして、次の結果を生成します。

$ツリー。
。
├──コンポーネント
│├──TestCommon
││├──pom.xml
││├──..。
││└──ターゲット
││├──maven-アーカイバ
│││└──pom.properties
││└──test-common-0.0.1-SNAPSHOT.jar
│├──TestOther
││├──pom.xml
││├──..。
││└──ターゲット
││├──maven-アーカイバ
│││└──pom.properties
││└──test-other-0.0.1-SNAPSHOT.jar
│├──TestPersistence
││├──pom.xml
││├──..。
││└──ターゲット
││├──maven-アーカイバ
│││└──pom.properties
││└──test-persistence-0.0.1-SNAPSHOT.jar
│└──TestWeb
│├──pom.xml
│├──src
││└──メイン
││└──webapp
││├──index.jsp
││└──WEB-INF
││└──web.xml
│└──ターゲット
│├──maven-アーカイバ
││└──pom.properties
│├──test-web-0.0.1-SNAPSHOT
││├──index.jsp
││├──META-INF
││└──WEB-INF
││├──クラス
││├──lib
│││├──test-common-0.0.1-SNAPSHOT.jar
│││├──test-other-0.0.1-SNAPSHOT.jar
│││└──test-persistence-0.0.1-SNAPSHOT.jar
││└──web.xml
│└──test-web-0.0.1-SNAPSHOT.war
└──pom.xml

したがって、問題はWARプロジェクト自体、その構造、またはこのようなものに関係している必要があります。その構造と実行時のMavenの出力を示してくださいwar:war


ちなみに、マルチモジュールビルドでのPOMの通常の外観は次のとおりです。

<project>
  <modelVersion>4.0.0</modelVersion>
  <!--groupId>com.test</groupId--> <!-- unnecessary, you inherit it -->
  <artifactId>test-web</artifactId>
  <packaging>war</packaging>
  <!--version>0.0.1-SNAPSHOT</version--> <!-- unnecessary, you inherit it -->
  <parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId> <!-- DRY, use built-in properties -->
      <artifactId>test-common</artifactId>
      <version>${project.version}</version> <!-- DRY, use built-in properties -->
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-persistence</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-other</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</project>

もう1つは、親プロジェクトからのwarプラグイン構成継承されます(Webモジュールで実行することで確認できhelp:effective-pomます)が、Webモジュール自体で構成することは理にかなっています。

于 2010-10-09T00:56:33.137 に答える