[英]Getting Error: Could not find or load main class while opening executable Jar file
我正在打開fontawesomefx-glyphsbrowser-all-1.0.jar
使用java -jar /home/ubuntu/Downloads/fontawesomefx-glyphsbrowser-all-1.0.jar
但出現錯誤
Could not find or load main class
還嘗試過:
java -cp /home/ubuntu/Downloads/fontawesomefx-glyphsbrowser-1.3.0/lib/fontawesomefx-glyphsbrowser-1.3.0.jar de.jensd.fx.glyphs.browser.GlyphsBrowser
並獲得:
Error: Could not find or load main class de.jensd.fx.glyphs.browser.GlyphsBrowser Caused by: java.lang.NoClassDefFoundError: javafx/scene/layout/VBox
另一個嘗試:
java -jar fontawesomefx-glyphsbrowser-all-1.0.jar
Error: Could not find or load main class de.jensd.fx.glyphs.browser.GlyphsBrowserApp
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
JavaFX 不再與 JDK 打包在一起,但我認為它來自 JDK 11,我使用的是 JDK 8,所以為什么我
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
我正在使用open-jdk 8.0
那怎么辦呢?
'main class not found' 錯誤有兩種情況:
.jar 包的 Manifest.MF 文件不包含有效的“Main-Class”屬性。 這可能是由於未正確創建 .jar 文件造成的。 這主要是創建 jar 文件的錯誤。
Jar 文件旨在用作庫,而不是用作可執行程序,因此,它不包含任何具有“main”方法的類。
對於案例#1(manifest.mf 中的錯誤),這些是可能的解決方法/修復:
要求 jar 文件的提供者在 manifest.mf 文件中使用正確的“Main-Class”定義再次創建它
將 jar 文件的內容解壓到一個目錄中,在 manifest.mf 文件中添加“Main-Class”屬性,然后再次將文件夾打包到 jar 中。
這是 Oracle 的一篇關於如何更新 manifest.mf 文件的文章:
https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
我設法通過使用Oracle JDK 8解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.