Ubuntu 18.10-如何使用Java安装JavaFX

时间:2019-01-07 13:51:51

标签: java ubuntu javafx

我同时安装了openjdk8和11。两者都不随JavaFX一起提供。 我同时安装了openjfx和libopenjfx-java软件包,但无法使我的应用程序正常工作。

sudo apt list --installed| grep jfx

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libopenjfx-java/cosmic,cosmic,now 11+26-4 all [installed]
libopenjfx-jni/cosmic,now 11+26-4 amd64 [installed,automatic]
openjfx-source/cosmic,cosmic,now 11+26-4 all [installed]
openjfx/cosmic,now 11+26-4 amd64 [installed]

Openjfx解压缩到/ usr文件夹

dpkg-query -L openjfx
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/openjfx
/usr/share/doc/openjfx/TODO.Debian
/usr/share/doc/openjfx/changelog.Debian.gz
/usr/share/doc/openjfx/copyright
/usr/share/openjfx
/usr/share/openjfx/lib
/usr/share/openjfx/lib/javafx.properties
/usr/share/openjfx/lib/javafx.base.jar
/usr/share/openjfx/lib/javafx.controls.jar
/usr/share/openjfx/lib/javafx.fxml.jar
/usr/share/openjfx/lib/javafx.graphics.jar
/usr/share/openjfx/lib/javafx.media.jar
/usr/share/openjfx/lib/javafx.swing.jar
/usr/share/openjfx/lib/javafx.web.jar

我应该将库复制到java lib文件夹吗?否则,它不会编译不存在的javafx.*软件包的笨拙

以前可以使用的jar现在退出:

Error: Could not find or load main class helloworld.HelloWorld
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

编辑

感谢@JoséPereda,我也许走了一步

java --module-path /usr/share/openjfx/lib --add-modules=javafx.controls,javafx.fxml

现在抛出

Caused by: java.lang.IllegalAccessError: class impl.org.controlsfx.version.VersionChecker (in unnamed module @0x28658d1c) cannot access class com.sun.javafx.runtime.VersionInfo (in module javafx.base) because module javafx.base does not export com.sun.javafx.runtime to unnamed module @0x28658d1c
    at impl.org.controlsfx.version.VersionChecker.<clinit>(VersionChecker.java:50)
    at org.controlsfx.control.ControlsFXControl.<init>(ControlsFXControl.java:35)
    at org.controlsfx.control.CheckComboBox.<init>(CheckComboBox.java:113)
    at org.controlsfx.control.CheckComboBox.<init>(CheckComboBox.java:104)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at java.base/java.lang.Class.newInstance(Class.java:584)
    at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1019)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
    at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)

1 个答案:

答案 0 :(得分:-1)

Ubuntu默认情况下具有openjdk,而openjdk不支持JavaFx。 卸载openjdk:

sudo apt-get purge openjdk-8-jre openjdk-8-jre-headless openjdk-7-jre gcj-4.7-base gcj-4.7-jre openjdk-6-jre-headless

sudo apt-get purge --auto-remove openjdk*

并安装oracle java

sudo add-apt-repository ppa:webupd8team/java
sudo apt update; sudo apt install oracle-java8-installer
sudo apt install oracle-java8-set-default