2012-01-02 30 views
11

Maven Shade PluginminimizeJarを使ってUberJarのサイズを最小限にしようとしています。 minimizeJarには、コード内に静的にインポートされたクラスしか含まれていないようです(uber jarをorg\apache\commons\logging\に入れているので、これが疑わしいですが、implパッケージのクラスが含まれていないので、uber-jarを実行するとjava.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImplクラスファイルを含むようにMaven Shade minimizeJarを設定します

minimizeJarの示唆にかかわらず、特定のパッケージを最終的なジャーに含めるようにMavenのShadeプラグインに指示する方法はありますか?ここで

私がしようとしています何のポンポンスニペット

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>1.5</version> 
     <executions> 
      <execution> 
       <phase>package</phase> 
       <goals> 
        <goal>shade</goal> 
       </goals> 
       <configuration> 
        <minimizeJar>true</minimizeJar> 
        <filters> 
         <filter> 
          <artifact>commons-logging:commons-logging</artifact> 
          <includes> 
           <include>org/apache/commons/logging/**</include> 
          </includes> 
         </filter>  
        </filters> 
        <transformers> 
         <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
          <mainClass>com.myproject.Main</mainClass> 
         </transformer> 
        </transformers>        
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 
+1

'org/apache/commons/logging/**'はディレクトリとのみ一致しますので、すべてのファイルを照合したいかもしれません。代わりに 'org/apache/commons/logging/**/*'を使用してください。 – Corubba

+0

あなたの提案に続いて、私は '... logging/**'、 '... logging/**/*'、 '... logging /**/*.*'を試みましたが、何も働かなかった。私は問題が含まれて最初に含まれていると思いますminimJarは、他のすべてを無視し、それが適切だと思うように瓶をバンドルします。 – kunal

答えて

14

この機能は、Mavenのシェード - プラグインのバージョン1.6に追加されました(リリースされたばかり)。 minimizeJarはフィルタに特別に含まれているクラスを削除しません。フィルタにアーティファクトのクラスの一部を含めると、そのアーティファクトの指定されていないクラスが除外されるため、必要なクラスをすべて含めるようにしてください。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <version>1.6</version>  
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals>       
      <configuration> 
       <minimizeJar>true</minimizeJar>  
       <filters> 
        <filter> 
         <artifact>log4j:log4j</artifact> 
         <includes> 
          <include>**</include> 
         </includes> 
        </filter> 
        <filter> 
         <artifact>commons-logging:commons-logging</artifact> 
         <includes> 
          <include>**</include> 
         </includes> 
        </filter>      
       </filters> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
+0

最下位レベルの「 **」は私には役に立たなかった。他のパッケージからもたくさんのものが入っているようです。代わりに ' org/apache/logging/log4j/** Log4j- *' – Quantum7

10

私はMavenのシェードプラグインのバージョン2.0を使用していますが、まだ私は「最小化」JAR後のクラスを含めることはできませんよ。

は、ここでは一例プラグインの設定です。

回避策として、必要なクラスへの参照を作成して最小化コードがそれらを取り除かないようにすることだけです。つまり、:

/* 
* This block prevents the Maven Shade plugin to remove the specified classes 
*/ 
static { 
    @SuppressWarnings ("unused") Class<?>[] classes = new Class<?>[] { 
     JButton.class, 
     JMenu.class, 
     JMenuBar.class, 
     JMenuItem.class 
    }; 
} 

私はMaven開発者がこの状況を処理する方法を実装してくれることを望みます(これは非常に一般的です)。

+0

という素晴らしい回避策を使用しなければなりませんでした。 – kunal

関連する問題