[特定のマニフェスト ファイルを使用するように、アセンブリとjarプラグインの両方を構成できます。アセンブリ ドキュメントの実行可能 Jarの作成セクションから:
お気づきのことと思いますが、Assembly プラグインは、プロジェクト用の自己完結型のバイナリ アーティファクトを作成するための非常に便利な方法です。ただし、この自己完結型の jar を作成したら、おそらく -jar JVM スイッチを使用して実行する機能が必要になるでしょう。
これに対応するために、Assembly Plugin は、maven-jar-plugin でサポートされているものと同じ要素の構成をサポートしています (「参考文献」を参照)。この構成を使用すると、jar マニフェストの Main-Class 属性を簡単に構成できます。
定義したマニフェストは、生成されたコンテンツとマージされることに注意してください。参照されたjarページから:
独自のマニフェスト ファイルのコンテンツは、Maven Archiver によって生成されたエントリとマージされます。独自のマニフェスト ファイルでエントリを指定すると、Maven Archiver によって生成された値が上書きされます。
次の構成は、アセンブリ プラグインの実行をpre-integration-test
フェーズ (パッケージの後の次のフェーズ) にバインドし、src/main/resources/META-INF で定義された MANIFEST.MF も含めます。
したがって、このアプローチに従って、共通のマニフェスト コンテンツを MANIFEST.MF で定義し、それらを最終的なマニフェストにマージすることができます。
src/main/resources/META-INF/MANIFEST.MF の内容
Created-By: Me
Foo: bar
Main-Class: com.foo.bar.MyMainClass
Bundle-Version: 4.0.0
更新: addDefaultSpecificationEntriesの
使用に関するコメントに基づいて、提案されたアプローチは、jar プラグインによって生成された jar の仕様と連携して機能します。ただし、アセンブリ プラグインは追加の宣言のマージをまだサポートしていないようです。jar プラグインは、src/main/resources のマニフェストを追加で指定された値とマージして、テスト プロジェクトにこのコンテンツを提供します。
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Me
Built-By: Rich Seller
Build-Jdk: 1.5.0_15
Specification-Title: Unnamed - org.test:test:jar:1.0.0
Specification-Version: 1.0.0
Implementation-Title: Unnamed - org.test:test:jar:1.0.0
Implementation-Version: 1.0.0
Implementation-Vendor-Id: org.test
Foo: bar
Main-Class: com.foo.bar.MyMainClass
Bundle-Version: 4.0.0
assembly-plugin からの出力は次のとおりです。
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Me
Foo: bar
Main-Class: com.foo.bar.MyMainClass
Bundle-Version: 4.0.0
構成:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-with-deps</id>
<phase>pre-integration-test</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifestFile>${manifest.file}</manifestFile>
<!--these properties are ignored-->
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifestFile>${manifest.file}</manifestFile>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
...
<properties>
<manifest.file>src/main/resources/META-INF/MANIFEST.MF</manifest.file>
</properties>