web-dev-qa-db-ja.com

Mavenですべての依存関係を持つZipを作成する

重複の可能性:
Mavenを使用して、プロジェクトのjarとすべての依存jarを持つディストリビューターを構築するにはどうすればよいですか?

私は盲目かもしれませんが、Mavenアセンブリプラグインは現在のproject.jarとすべての依存関係jarを含むZipファイルを作成できますか? 「bin」IDには私のproject.jarだけが含まれ、jar-with-dependenciesはすべてを1つのjarにまとめますが、これは気に入らないものです。

16
Jan

必要なことを行うには、カスタムアセンブリ記述子が必要です。これは、binとjar-with-dependenciesの事前定義された記述子の組み合わせです。 Assembly.xmlフォルダーにsrc/main/Assemblyというカスタムアセンブリ記述子を作成しました。

これは基本的に依存関係セットが追加されたbin記述子である例です:

    <Assembly xmlns="http://maven.Apache.org/plugins/maven-Assembly-plugin/Assembly/1.1.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.Apache.org/plugins/maven-Assembly-plugin/Assembly/1.1.0 http://maven.Apache.org/xsd/Assembly-1.1.0.xsd">
  <id>bin</id>
  <formats>
    <format>tar.gz</format>
    <format>tar.bz2</format>
    <format>Zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>README*</include>
        <include>LICENSE*</include>
        <include>NOTICE*</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>${project.build.directory}/site</directory>
      <outputDirectory>docs</outputDirectory>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</Assembly>

次に、pomを変更して、descriptorRefの代わりに記述子を使用してカスタム記述子がどこにあるかを伝えます。

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-Assembly-plugin</artifactId>
        <version>2.2.1</version>
        <configuration>
          <descriptors>
            <descriptor>src/main/Assembly/assembly.xml</descriptor>
          </descriptors>
        </configuration>
        [...]
</project>
30
jewles

見てください ここ 例502 ...すべての依存関係などをtar.gz/Zipなどにパッケージ化する方法の例があります。

2
khmarbaise

fat-jar プラグインを見てください。

1