如何安装JavaFX

Posted dingdingfish

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何安装JavaFX相关的知识,希望对你有一定的参考价值。

JavaFX的官方网站在这里,从JDK 11开始,javaFX未包含在JDK中。

安装过程如下:

  1. 安装JDK,本例为JDK 11,下载地址
  2. 下载JavaFX 11,下载地址
  3. 安装JavaFX 11
    首先找到当前SDK的路径 ->/usr/java/jdk-11.0.4:
# which javac
/bin/javac
# ls -l javac
lrwxrwxrwx. 1 root root 23 Aug 19 11:09 javac -> /etc/alternatives/javac
# cd /etc/alternatives/
# ls -l javac
lrwxrwxrwx. 1 root root 30 Aug 19 11:09 javac -> /usr/java/jdk-11.0.4/bin/javac
# cd /usr/java
# ls
default  jdk-11.0.4  latest
# cd jdk-11.0.4/
# ls
bin  conf  include  jmods  legal  lib  README.html  release
# pwd
/usr/java/jdk-11.0.4

解压JavaFX到当前JDK目录:

# unzip /mnt/openjfx-11.0.2_linux-x64_bin-sdk.zip -d /usr/java/jdk-11.0.4/
Archive:  /mnt/openjfx-11.0.2_linux-x64_bin-sdk.zip
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libjavafx_font_freetype.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libglassgtk3.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx-swt.jar  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libjavafx_iio.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libprism_sw.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libglassgtk2.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libprism_common.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libglass.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx.properties  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libprism_es2.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libfxplugins.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libjfxwebkit.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx.base.jar  
 extracting: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/src.zip  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libdecora_sse.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx.controls.jar  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libavplugin-54.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libjavafx_font_pango.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libgstreamer-lite.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libavplugin-56.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libavplugin-ffmpeg-56.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libavplugin-57.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libjavafx_font.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx.fxml.jar  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx.swing.jar  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx.graphics.jar  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libavplugin-ffmpeg-57.so  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx.web.jar  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/javafx.media.jar  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib/libjfxmedia.so  
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.base/
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.base/ASSEMBLY_EXCEPTION  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.base/LICENSE  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.base/ADDITIONAL_LICENSE_INFO  
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.graphics/
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.graphics/ASSEMBLY_EXCEPTION  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.graphics/jpeg_fx.md  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.graphics/LICENSE  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.graphics/ADDITIONAL_LICENSE_INFO  
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.controls/
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.controls/ASSEMBLY_EXCEPTION  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.controls/LICENSE  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.controls/ADDITIONAL_LICENSE_INFO  
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.fxml/
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.fxml/ASSEMBLY_EXCEPTION  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.fxml/LICENSE  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.fxml/ADDITIONAL_LICENSE_INFO  
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.web/
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.web/ASSEMBLY_EXCEPTION  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.web/libxml2.md  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.web/LICENSE  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.web/icu_web.md  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.web/webkit.md  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.web/ADDITIONAL_LICENSE_INFO  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.web/libxslt.md  
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.swing/
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.swing/ASSEMBLY_EXCEPTION  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.swing/LICENSE  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.swing/ADDITIONAL_LICENSE_INFO  
   creating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.media/
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.media/glib.md  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.media/ASSEMBLY_EXCEPTION  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.media/LICENSE  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.media/libffi.md  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.media/gstreamer.md  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.media/applecoreaudio.md  
  inflating: /usr/java/jdk-11.0.4/javafx-sdk-11.0.2/legal/javafx.media/ADDITIONAL_LICENSE_INFO
  1. 测试
export PATH_TO_FX=/usr/java/jdk-11.0.4/javafx-sdk-11.0.2/lib
javac --module-path $PATH_TO_FX --add-modules javafx.controls JavaFXSkel.java
java --module-path $PATH_TO_FX --add-modules javafx.controls JavaFXSkel

参考

  1. https://openjfx.io/openjfx-docs/#introduction
  2. https://gluonhq.com/products/javafx/
  3. http://comfilewiki.co.kr/en/doku.php?id=comfilepi:install_the_oracle_jdk_and_openjfx:index

以上是关于如何安装JavaFX的主要内容,如果未能解决你的问题,请参考以下文章

JavaFX开发环境安装配置

如何在 Netbeans 11 中使用 Maven 和 Inno Setup 为 JavaFX 应用程序创建可执行安装程序

我安装了“Java”和“JavaFX”,如何打开操作界面啊

如何获取 JavaFX 的版本号?

如何使用 maven 部署 JavaFX 项目,包括自定义和非模块化依赖项?

如何使用 JavaFX 和 scenebulider 配置 IntelliJ IDEA?