Getting Error: Could not find or load main class while opening executable Jar file
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 is no longer packaged with JDK but I think it is from JDK 11 and I'm using JDK 8 so why I'm getting Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
I'm using open-jdk 8.0
那么怎么办?
'main class not found' 错误出现在 2 种情况下:
.jar 包的 Manifest.MF 文件不包含有效的 'Main-Class' 属性。这可能是由于未正确创建 .jar 文件所致。这主要是创建 jar 文件的错误。
Jar 文件旨在用作库,而不是可执行程序,因此,它不包含任何 class 和 '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.
解决了这个问题
我正在打开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 is no longer packaged with JDK but I think it is from JDK 11 and I'm using JDK 8 so why I'm getting
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
I'm usingopen-jdk 8.0
那么怎么办?
'main class not found' 错误出现在 2 种情况下:
-
.jar 包的
Manifest.MF 文件不包含有效的 'Main-Class' 属性。这可能是由于未正确创建 .jar 文件所致。这主要是创建 jar 文件的错误。
Jar 文件旨在用作库,而不是可执行程序,因此,它不包含任何 class 和 '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.
解决了这个问题