我尝试将我的javafx应用程序压缩到jar中,当我运行时:
java -jar /home/roroco/Dropbox/rbs/ro_cmds_global/j/fileToClip/build/libs/server-1.0.jar -cp /home/roroco/Downloads/jdk1.8.0_74/jre/lib/ext/jfxrt.jar
它引发了这个错误:
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
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)
我确定jfxrt.jar包含javafx.application.Application
roroco@roroco /tmp/fileToClip $ jar tf
/home/roroco/Downloads/jdk1.8.0_74/jre/lib/ext/jfxrt.jar|gr Application\.class
com/sun/glass/ui/Application.class
com/sun/glass/ui/gtk/GtkApplication.class
javafx/application/Application.class
为什么它会引发“ClassNotFoundException”?
更新
我的java版本是:
roroco@roroco ~/Dropbox/try/j/try $ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~14.04-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
答案 0 :(得分:2)
我找到原因:因为我的java版本是:
roroco@roroco ~/Dropbox/try/j/try $ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~14.04-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
我应该使用oracle bin / java代替,在我的情况下,我使用以下将工作:
/home/roroco/Downloads/jdk1.8.0_74/bin/java -jar /home/roroco/Dropbox/rbs/ro_cmds_global/j/fileToClip/build/libs/server-1.0.jar
答案 1 :(得分:0)
问题可能是你的IDE中的de java版本与你的“java”comamnd时你的linux的java版本不一样。