2016-12-05 1 views
-1

気象データを自動的にダウンロードし、特定の場所のこれらのデータをデータベースに追加するためのアプリケーションを作成しました。このアプリケーションはIntelliJ内で意図したとおりに動作しますNoClassDefFoundError(Macではなく)

このアプリケーションをスタンドアロンアプリケーションとして実行します。したがって、私はmavenを使ってjarファイルを作成しました。 jarはすべての依存関係のない "無駄のない" jarです。依存関係はディレクトリlibに出力されます。 Mavenのプラグインのように構成されています

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <classpathPrefix>lib/</classpathPrefix> 
         <mainClass>nl.wur.fbr.data.weather.WeatherData</mainClass> 
        </manifest> 
       </archive> 
       <outputDirectory>${project.build.directory}/WeatherData</outputDirectory> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>install</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>${project.build.directory}/WeatherData/lib</outputDirectory> 
         <overWriteReleases>true</overWriteReleases> 
         <overWriteSnapshots>true</overWriteSnapshots> 
         <overWriteIfNewer>true</overWriteIfNewer> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

クラスパスをマニフェストに追加された(私がチェックした)とすべての依存関係は、libディレクトリに出力されます。

このアプリケーションをMac(Javaバージョン1.8.0)で実行すると、すべて正常に動作します。しかし、私は(ビュンと解凍し、また、Java 1.8.0を実行した後)のLinuxサーバー上でそれを実行したときに、私は次のエラーを取得する:通常

$ java -jar weatherData-1.0-SNAPSHOT.jar 
Error: A JNI error has occurred, please check your installation and try again 
Exception in thread "main" java.lang.NoClassDefFoundError: nl/wur/fbr/om/factory/InstanceFactory 
    at java.lang.Class.getDeclaredMethods0(Native Method) 
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) 
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048) 
    at java.lang.Class.getMethod0(Class.java:3018) 
    at java.lang.Class.getMethod(Class.java:1784) 
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) 
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) 
Caused by: java.lang.ClassNotFoundException: nl.wur.fbr.om.factory.InstanceFactory 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    ... 7 more 

クラスパスの問題が、なぜそれはMacOSXの上で異なる動作をだろうとLinuxで?メインjarファイル(クラスパスを含むマニフェスト付き)とlibディレクトリは同じです。

+0

私にとっては、依存関係に 'nl.wur.fbr.om.factory.InstanceFactory'がありません。多分あなたは手動でそれをMacに追加しましたか? – XtremeBaumer

+0

"full" JARをビルドするために 'maven-shade-plugin'を使うことを検討してください。それはしばしばより良い選択肢です。 – lexicore

+0

@XtremeBaumerそのライブラリを含むjarファイルはlibディレクトリにあります。私は手動で私のMacにそれを追加したことはない。もちろん、私のMavenリポジトリにあります。しかし、私はスタンドアロンアプリケーションを実行するときにmavenを使用しません。 –

答えて

1
I am not sure what is exactly causing this issue but below steps might help to narrow down the path. 

Step 1 : Verify the class file nl.wur.fbr.om.factory.InstanceFactory present inside jar 

Step 2: Verify MANIFEST.MF file and check for the following entries - 
ex: Main-Class: nl.wur.fbr.data.weather.WeatherData 
Class-Path: 
    ../config/ 
    classes12.jar 
    bc4jct.jar 
    bc4jdomorcl.jar 
    bc4jmt.jar 
    commons-beanutils-bean-collections.jar 
    commons-beanutils-core.jar 

Step 3 : Verify the jar entry is present in Class-Path 

Step 4: If the issue still persists, try running with java -classpath option. 
+0

私はあなたの手順を試しましたが、今はOMライブラリの問題と思われます。どうやら、 'InstanceFactory'が含まれているライブラリは' lib/om-java-model-0.6.0-SNAPSHOT.jar'であり、マニフェストでは 'lib/OM-java-model-0.6.0-SNAPSHOT。瓶。大文字に注意してください。図書館に首都が含まれていないのに、なぜ大文字でマニフェストを書くのですか? –

+0

それが問題でした。私の管理下にあるOMライブラリでは、大文字と小文字が混在していました。私はそのライブラリのpomファイルを編集しました。そして、参照が正しく設定されました。 –