質問

私は持っています メイベン プロジェクト、4つのコンポーネントWeb、永続性、共通、その他。

関連するものは私のものです ポン ファイル:

親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>

Web 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パッケージを実行するとき、プロジェクト 戦争ファイル 作成されていませんが、すべてのコンポーネントパッケージは作成され、適切に形成されています。
  • もしそうなら、私は実行します mvn war:war, 、戦争ファイルが空に生成されます。

これを修正するにはどうすればよいですか?

役に立ちましたか?

解決

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

<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のモジュールの順序が、プロジェクト間の依存関係に整合していることを確認してください(場合は注文を逆にするだけです)。

他のヒント

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

$ mvn package 
[INFO] Scanning for projects...
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Unnamed - com.test:test:pom:0.0.1-SNAPSHOT ............ SUCCESS [5.819s]
[INFO] Unnamed - com.test:test-common:jar:0.0.1-SNAPSHOT ..... SUCCESS [3.343s]
[INFO] Unnamed - com.test:test-persistence:jar:0.0.1-SNAPSHOT  SUCCESS [0.136s]
[INFO] Unnamed - com.test:test-other:jar:0.0.1-SNAPSHOT ...... SUCCESS [0.079s]
[INFO] Unnamed - com.test:test-web:war:0.0.1-SNAPSHOT ........ SUCCESS [1.899s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...

次の結果を生成します。

$ tree .
.
├── components
│   ├── TestCommon
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-common-0.0.1-SNAPSHOT.jar
│   ├── TestOther
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-other-0.0.1-SNAPSHOT.jar
│   ├── TestPersistence
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-persistence-0.0.1-SNAPSHOT.jar
│   └── TestWeb
│       ├── pom.xml
│       ├── src
│       │   └── main
│       │       └── webapp
│       │           ├── index.jsp
│       │           └── WEB-INF
│       │               └── web.xml
│       └── target
│           ├── maven-archiver
│           │   └── pom.properties
│           ├── test-web-0.0.1-SNAPSHOT
│           │   ├── index.jsp
│           │   ├── META-INF
│           │   └── WEB-INF
│           │       ├── classes
│           │       ├── 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

したがって、あなたの問題は、あなたの戦争プロジェクト自体、その構造、またはこのようなものと関係がなければなりません。実行時にMavenの構造と出力を表示してください war:war その上。


ちなみに、Multi-Modulesビルドで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>

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top