2009-10-05 19 views
27

私は、(私のJavaプロジェクトの依存関係を持つ実行可能なjarファイルを含む)配布ZIPファイルを作成しようとしています。maven-assemblyプラグイン - ネストされたアセンブリを作成する方法

だから私は一種のそれは次のようになりたい:

-wiki-search-1.0.0-dist.zip 
    -wiki-search.bat 
    -wiki-search-help.html 
    -wiki-search-1.0.0-jar-with-dependencies.jar 
     -jar content... 

私は、実行可能jarファイルを作成するために、アセンブリのプラグインを使用して、事前に定義された記述子「ジャーとの依存関係」です。

個別のアセンブリプラグインエントリをpomに指定し、カスタムディスクリプタを参照して、配布可能なzipファイルを作成します。

だから私のポンポンの一部は次のようになります。

<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<configuration> 
    <descriptorRefs> 
    <descriptorRef>jar-with-dependencies</descriptorRef> 
    </descriptorRefs> 
    <archive> 
    <manifest> 
    <mainClass>quicksearch.QuickSearchApp</mainClass> 
    </manifest> 
    </archive> 
</configuration> 
<executions> 
    <execution> 
    <id>make-assembly</id> 
    <phase>package</phase> 
    <goals> 
    <goal>attached</goal> 
    </goals> 
    </execution> 
</executions> 
</plugin> 
<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<configuration> 
    <descriptors> 
    <descriptor>src/main/assembly/dist.xml</descriptor> 
    </descriptors> 
</configuration> 
<executions> 
    <execution> 
    <id>make-assembly</id> 
    <phase>package</phase> 
    <goals> 
    <goal>attached</goal> 
    </goals> 
    </execution> 
</executions> 
</plugin> 

そして、私のカスタム記述子は次のようになります。

<assembly> 
    <id>dist</id> 
    <formats> 
    <format>tar.gz</format> 
    <format>tar.bz2</format> 
    <format>zip</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <includes> 
     <include>${project.basedir}/target/wiki-search-0.0.1-SNAPSHOT-jar-with-dependencies.jar</include> 
     </includes> 
     <outputDirectory>.</outputDirectory> 
    </fileSet> 
    <fileSet> 
     <directory>${project.basedir}/src/main/etc</directory> 
     <includes> 
     <include>*</include> 
     </includes> 
    <outputDirectory></outputDirectory> 
    </fileSet> 
    </fileSets> 
</assembly> 

すべてが正常に動作します。 jar-with-dependenciesが構築されています。私のdist zipファイルが構築されています。しかし、dist zipファイルにはjar-with-dependenciesファイルが含まれていません。

答えて

43

既存の設定では、アセンブリプラグインの2つの別々の設定がマージされ、設定もマージされます。

目的を達成するには、複数のネストされた実行を持つ1つのアセンブリプラグイン構成を定義し、その中に実行ごとの構成を定義する必要があります。アセンブリプラグインは各アセンブリを順番に実行しますので、 jarファイルをdist jarに含めることができます。またattachedの目標は、singleの目標を支持して廃止されました。

アセンブリ内のパスはルートからの相対パスであり、特定のファイルを含めるには、<filesets>要素ではなく<files>要素を使用する必要があります。また、アセンブリのプロパティを指定して、変更しにくくすることもできます。

アセンブリ・ディスクリプタ:

<assembly> 
    <id>dist</id> 
    <formats> 
    <format>tar.gz</format> 
    <format>tar.bz2</format> 
    <format>zip</format> 
    </formats> 
    <files> 
    <file> 
     <source> 
     target/${project.artifactId}-${project.version}-jar-with-dependencies.jar 
     </source> 
     <outputDirectory>/</outputDirectory> 
    </file> 
    </files> 
    <fileSets> 
    <fileSet> 
     <directory>${project.basedir}/src/main/resources</directory> 
     <includes> 
     <include>*</include> 
     </includes> 
    <outputDirectory>/</outputDirectory> 
    </fileSet> 
    </fileSets> 
</assembly> 

アセンブリプラグイン:

<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<executions> 
    <execution> 
    <id>jar-with-dependencies</id> 
    <phase>package</phase> 
    <goals> 
    <goal>single</goal> 
    </goals> 
    <configuration> 
    <descriptorRefs> 
    <descriptorRef>jar-with-dependencies</descriptorRef> 
    </descriptorRefs> 
    <archive> 
    <manifest> 
     <mainClass>quicksearch.QuickSearchApp</mainClass> 
    </manifest> 
    </archive> 
    </configuration> 
    </execution> 
    <execution> 
    <id>dist</id> 
    <phase>package</phase> 
    <goals> 
    <goal>single</goal> 
    </goals> 
    <configuration> 
    <descriptors> 
    <descriptor>src/main/assembly/dist.xml</descriptor> 
    </descriptors> 
    </configuration> 
    </execution> 
</executions> 
</plugin> 
+3

+1非常に素晴らしいと詳細な回答 –

+0

伝説以下

再編成された構成や組み立てはあなたが後にしている何をすべき。初めての作業。乾杯。 – Ben

+0

ありがとう!実行をデフォルトのライフサイクルに取り付けることなくこれを達成する方法はありますか? 「フェーズ」と「ゴール」の要素を省略するだけではうまくいきませんでした。 –

0

アセンブリプラグインには2つの異なる設定があり、それらを順番に実行する(zipより前のjar)が、Mavenにはこれがどのように解決されるかは関係ありません。私の推測では、zipファイルがJARファイルの前に生成されているということです。

そうでない場合でも、アーティファクトごとに1つのモジュールを作成することをお勧めします。 JARアセンブリを独自のモジュールに移動し、今すぐZipのみのモジュールに依存させます。そうすれば、Mavenの依存関係の順序の解決が始まり、順番にそれを構築することができます。

関連する問題