2009-06-09 3 views
8

私はMaven 2アセンブリプラグインを使用してjar-with-dependenciesを構築し、実行可能なJARファイルを作成しています。私のアセンブリにはSpringとCXFライブラリが含まれています。Maven 2アセンブリプラグインがいくつかのMETA-INFファイルをクローバーします

CXFには、spring.schemasとspring.handlersのMETA-INFファイルのコピーが含まれているため、spring-2.5.4 jarの同様のファイルが壊れてしまいます。

手作業でjar-with-dependencies内の2つのファイルを更新できます。

私が探しているのは、これらの2つのファイルの正しいバージョンを取得するためにアセンブリプラグインを指示するMaven POMのやり方です。

アセンブリプラグインのドキュメントでは、ファイルフィルタリングについて説明していますが、カスタムアセンブリディスクリプタを作成する手間を省くことなく、またはパラメータ用の構成がないようです。

このインスタンスでカスタムアセンブリ記述子を唯一の希望ですか?

+0

同じことが「spring.tooling」ファイルで発生しますが、その名前から、私は、彼らが実行時に使用されていない推測しています。 –

答えて

6

何らかの理由で、モジョと他の人たちが提案している解決策は、私にとってはうまくいきません。私は自分のカスタムspring.handlersspring.schemasファイルを作成し、それをsrc/main/resources/META-INFに入れました。しかし、unpackOptionsを使用すると、私のファイルも含まれていません。私がunpackOptionsを使用しないとき、私のファイルはjarファイル内のファイルではありません。

私がやったことは、ファイルを直接参照することでした。これは最終的に私のファイルをJARに入れました。

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 
    <!-- TODO: a jarjar format would be better --> 
    <id>jar-with-dependencies</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
     <dependencySet> 
      <outputDirectory>/</outputDirectory> 
      <unpack>true</unpack> 
      <unpackOptions> 
       <excludes> 
        <exclude>META-INF/spring.handlers</exclude> 
        <exclude>META-INF/spring.schemas</exclude> 
       </excludes> 
      </unpackOptions> 
      <scope>runtime</scope> 
     </dependencySet> 
    </dependencySets> 
    <files> 
     <file> 
      <source>${project.basedir}/src/main/resources/META-INF/spring.handlers</source> 
      <outputDirectory>META-INF</outputDirectory> 
     </file> 
     <file> 
      <source>${project.basedir}/src/main/resources/META-INF/spring.schemas</source> 
      <outputDirectory>META-INF</outputDirectory> 
     </file> 
    </files> 
</assembly> 
+0

確かに、このソリューションはより良く、より一般的です。以前の除外が何らかの理由で私のために働いていなかったとき、私は自分自身に没頭しなければなりませんでした。 – Mojo

+0

同じプロジェクトにクラスを含めるには、 trueを追加する必要がありました。 – jontro

1

が、私はそれを働いて、ここで詳細は以下のとおりです。

まず、ファイルあなたは、組み込みのアセンブリ・ディスクリプタジャー-との依存関係を使用する場合は含まれまたは除外を指定する方法はありません。

アセンブリプラグインのマニュアルには、サンプルjar-with-dependencies descriptor hereが記載されています。

私のプロジェクトディレクトリのexec-jar.xmlというファイルにそのディスクリプタをコピーして貼り付けました。次に、pomで、そのディスクリプタを参照するようにアセンブリプラグインを変更しました。以下はその抜粋です:ディスクリプタの

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.2-beta-3</version> 
     <configuration> 
      <descriptors> 
       <descriptor>exec-jar.xml</descriptor> 
      </descriptors> 
      <archive> 
       <manifest> 
        <mainClass>com.package.MyMainClass</mainClass> 
       </manifest> 
      </archive> 
     </configuration> 
     <executions> 
      <execution> 
       <id>make-assembly</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

そのビットは、exec-jar.xml記述子のライフサイクルのパッケージ段階にアセンブリを結合し、および参照。そのパッケージを実行することで、jarファイルがあらかじめ定義された記述子と同じように構築されたことが確認されました。

したがって、exec-jar.xmlを変更して、Springファイルと競合するCXFファイルを除外します。ここでそれを達成した私のアセンブリ記述子は次のとおりです。

<assembly> 
    <id>jar-with-dependencies</id> 
    <formats> 
    <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
    <dependencySet> 
     <unpack>true</unpack> 
     <unpackOptions> 
     <excludes> 
      <exclude>cxf*/META-INF/spring.handlers</exclude> 
      <exclude>cxf*/META-INF/spring.schemas</exclude> 
     </excludes> 
     </unpackOptions> 
     <scope>runtime</scope> 
    </dependencySet> 
    </dependencySets> 
    <fileSets> 
    <fileSet> 
     <directory>${project.build.outputDirectory}</directory> 
    </fileSet> 
    </fileSets> 
</assembly> 

ここでは擦れです。現在リリースされているアセンブリプラグインバージョン2.1でこれを行うと、タグで「予期しない」エラーが発生します。このタグは、リリースされていないバージョン2.2のプラグインでサポートされています。上記の私のpomファイルの抜粋では、作成時に最新のmaven-assembly-pluginバージョン2.2-beta-3を指定しています。

これは、実行可能なjarを正常に構築しました。Springには、アプリケーションの初期化に必要なすべてのハンドラとスキーマが用意されていました。

5

代わりにmaven-shade-pluginを使用することをお勧めします。 cxfバンドル(http://svn.apache.org/repos/asf/cxf/trunk/distribution/bundle/all/pom.xml)のpomを見ると、shadeトランスフォーマーを使用してspring.schemasと他の必要なファイルをマージする方法がわかります。

+0

これは、http://www.hagelnx.com/prog/814でもうまく説明されています。 –

1

spring.schemasファイルとspring.handlersファイルを必要なスプリングディストリビューションから取得してプロジェクトsrc/main/resources/META-INFディレクトリに配置することで、この問題を回避することもできます。それらは最後にパッケージ化されているので、あなたはあなたが望むバージョンを手に入れます。私はそのアイデアを見つけたhere

5

私は陰影のプラグインのアプローチを試してみましたが、とてもうまく機能しました。 POMに組み込む必要があるのはこれだけです(アセンブリプラグインは必要ありません)。

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.4</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <transformers> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <mainClass>org.example.Runner</mainClass> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
           <resource>META-INF/spring.handlers</resource> 
          </transformer> 
         </transformers> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
+0

これは私のために働いた –

関連する問題