簡體   English   中英

獨立應用程序中的Spark Java錯誤

[英]Spark Java error in standalone application

我能夠使用launch4j創建可執行文件,並且在我的機器上可以正常工作。 當我將其發送給某人在其Windows計算機上運行時,他們收到以下錯誤:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: spark/TemplateEngine
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: spark.TemplateEngine
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more

有什么想法嗎?

我遇到這個問題是因為我的默認Java版本是9,Spark無法識別它。 因此,我更改為版本8並成功了。 要在linux中更改:

sudo update-java-alternatives -s java-1.8.0-openjdk-amd64

在您的情況下,您可能需要另一個版本,因此選擇您的版本(使用-l選項列出您計算機中的版本)。

必須在類路徑中設置相對路徑,以便可執行文件可以找到jar文件

如果您的Maven依賴項未將<scope>設置為編譯時(默認),並且依賴項jar在編譯時不可用,則也可能發生此異常。 例如,如果您的pom.xml編譯器中已<scope>provided</scope> maven依賴項<scope>provided</scope> ,則編譯器將假定JRE /環境將提供這些依賴項jar,但是當編譯源並且未找到這些依賴項時,將拋出此異常。

例如-如果在編譯期間未找到spark-mllib_2.11依賴關系(盡管已添加它們並且在編輯過程中沒有錯誤),則可能導致以下異常:

<dependency>
   <groupId>org.apache.spark</groupId>
   <artifactId>spark-mllib_2.11</artifactId>
   <version>2.2.0</version>
   <scope>provided</scope>
</dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM