21

アンパックされた依存 jarを含むクライアント jar を構築しようとしています。マニフェストにはclass-path、依存する jar へのエントリが必要です。以下のスニペットは機能しますが、jar はアンパックされています。jar がアンパックされないようにするにはどうすればよいでしょうか?

       <plugin>
            <artifactId>maven-assembly-plugin</artifactId>

            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>

                <archive>
                  <manifest>
                    <addClasspath>true</addClasspath>
                  </manifest>
                </archive>
            </configuration>

            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
4

3 に答える 3

21

実際、usingを使用すると、対応するアセンブリ記述子で設定されているようにjar-with-dependencies、mavenがすべての依存関係をアンパックします。${assembly.dependencySets.dependency.unpack}true

簡単な修正は、に似たアセンブリ記述子を提供し、次のようjar-with-dependencies.xmlに変更する${assembly.dependencySets.dependency.unpack}ことです。false

編集:不明な理由により、使用時の動作<unpack>false</unpack>はまったく同じではなく<outputDirectory>/</outputDirectory>、fileSetに追加する必要があるようです。そうしないと、期待した結果が得られません。

<assembly>
  <id>uberjar</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>false</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>${project.build.outputDirectory}</directory>
      <outputDirectory>/</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>
于 2009-11-18T21:21:17.460 に答える
6

依存関係を jar ファイルとして jar に追加できます。

アセンブリ記述子.xml

<assembly>
    <id>uberjar</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <unpack>false</unpack>
            <scope>runtime</scope>
            <useProjectArtifact>false</useProjectArtifact>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>${project.build.outputDirectory}</directory>
            <outputDirectory>.</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>make-uberjar</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptor>src/main/assemble/assembly-descriptor.xml</descriptor>
            </configuration>
        </execution>
    </executions>
</plugin>

Class-Path残念ながら、 でヘッダーを使用することはできません。「クラスを JAR ファイルのクラスパスに追加するmanifest.mf」を参照してください。

注:ヘッダーはClass-Path、JAR ファイル内の JAR ファイルやインターネット プロトコル経由でアクセス可能なクラスではなく、ローカル ネットワーク上のクラスまたは JAR ファイルを指します。JAR ファイル内の JAR ファイル内のクラスをクラス パスにロードするには、これらのクラスをロードするカスタム コードを記述する必要があります。たとえば、MyJar.jarという別の JAR ファイルが含まれている場合、マニフェストのヘッダーを使用してクラスをクラス パスにロードMyUtils.jarすることはできません。Class-PathMyJar.jar'sMyUtils.jar

于 2016-01-19T14:32:57.810 に答える
3

Pascal Thivent によって提案されたソリューションは、Maven アセンブリ プラグインの新しいアセンブリを定義します。Maven アセンブリ プラグインは、さまざまな定義済みバンドルを生成する「bin」、「jar-with-dependencies」、「project」、および「src」であるデフォルト アセンブリを提供します。

新しいアセンブリは、ほとんどの場合、src/assembly にある新しい xml ファイルで定義する必要があります。次に、事前定義されたものの代わりに、次のようにロードされます。

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.2-beta-5</version>
      <configuration>

          <!-- disabled predefined assembly -->
          <!--
          <descriptorRefs>
             <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          -->

          <descriptors>
             <descriptor>src/assemble/myAssembly.xml</descriptor>
          </descriptors>
      </configuration>
</plugin>
于 2010-11-28T19:39:40.930 に答える