1

インストーラー サブプロジェクトを含むマルチモジュール Maven プロジェクトがあります。インストーラーは、実行可能な JAR として配布されます。DB をセットアップし、WAR ファイルをアプリ サーバーに抽出します。Maven を使用して、この jar を次のように組み立てたいと思います。

/META-INF/MANIFEST.MF
/com/example/installer/Installer.class
/com/example/installer/...
/server.war

マニフェストには、インストーラー クラスを指すメインクラス エントリがあります。この方法で jar を作成するにはどうすればよいでしょうか?

4

1 に答える 1

3

Mavenアセンブリプラグインを使用してjarをビルドできます。

まず、結果のjarを実行可能にするために、pom.xmlプラグインセクションにいくつかの情報を追加する必要があります。

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>com.example.installer.Installer</mainClass>
      </manifest>
    </archive>
  </configuration>
</plugin>


別のアセンブリ記述子を使用して、実際のインストーラーjarをビルドすること をお勧めします。次に例を示します。

<assembly>
  <id>installer</id>

  <formats>
    <format>jar</format>
  </formats>

  <baseDirectory></baseDirectory>

  <dependencySets>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <includes>
        <!-- this references your installer sub-project -->
        <include>com.example:installer</include>
      </includes>
      <!-- must be unpacked inside the installer jar so it can be executed -->
      <unpack>true</unpack>
      <scope>runtime</scope>
    </dependencySet>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <includes>
        <!-- this references your server.war and any other dependencies -->
        <include>com.example:server</include>
      </includes>
      <unpack>false</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>


アセンブリ記述子を「installer.xml」として保存した場合は、次のようにアセンブリを実行してjarをビルドできます。

mvn clean package assembly:single -Ddescriptor = installer.xml


お役に立てれば。役立つと思われる追加のリンクを次に示します。

于 2008-11-29T21:55:45.560 に答える