How to install Liberica JDK / Creating a JavaFX development environment with OpenJDK and OpenFX
このページを日本語で見る
Contents
- To solve 'Error: Module not found: javafx.controls'
- Preparing for JDK installation
- Download Liberica JDK
- Installing Liberica JDK
- Check JDK installation results
- Compile and run JavaFX sample program
- To solve runtime error 'JavaScript script engine is disabled'
- How to check and change Windows system environment variables
To solve 'Error: Module not found: javafx.controls'
It's been a few years since Java left Oracle's hands and JavaFX spun off. The development environment for Java and JavaFX has completely changed. In building the latest JavaFX development environment, We first took the direct approach (?) and built the environment by downloading OpenJDK and OpenFX separately, but somehow the errorError: Module not found: javafx.controls
could not be resolved.
While investigating various things, we learned the existence of Liberica JDK provided by BellSoft as a JDK with OpenFX built in, and tried this. This error was immediately resolved.
On this page, we will explain how to compile and run the JavaFX sample code "HelloFX.java" using this Liberica JDK.
OpenJDK official site
OpenFX official site
BellSoft official site
Liberica JDK official site
Preparing for JDK installation
No special preparation is required to install the Liberica JDK. However, if you have used other Java JDKs in the past, you should uninstall them beforehand.If there is a JDK name on the [Start]-[Settings]-[Apps] screen, [Uninstall] from here. If you install manually, organize the Windows system environment variables "Path", "JAVA_HOME", and "PATH_TO_FX".
If the path to another Java JDK remains in the environment variable "Path", delete only that part.
If the environment variables "JAVA_HOME" and "PATH_TO_FX" are defined, delete them.
If other environment variables related to JDK and JavaFX were defined, delete them.
If you want to use multiple JDKs, leave the installation folder of each JDK and switch by editing the above system environment variables.
How to check and change Windows system environment variables
Download Liberica JDK
Liberica JDK download page
"MSI" is a module with an installer. The installation folder will be automatically selected and environment variables will be set. You can download a file named "bellsoft-jdk17.0.6+10-windows-amd64-full.msi".
"ZIP" is the zipped JDK installation folder. This is also useful if you want to extract the JDK to any folder. However, setting environment variables must be done manually. You can download a file named "bellsoft-jdk17.0.6+10-windows-amd64-full.zip".
How to check and change Windows system environment variables
Installing Liberica JDK
Default install location is "C:\Program Files\BellSoft\LibericaJDK-17-Full".
If you want to change the installation destination, click the "Browse" button and specify a new installation destination.
Check JDK installation results
Make sure JDK is installed correctly. Open a console and type
java -version
. If the Java version is displayed as shown, it is installed correctly.
You should now be able to compile java programs using javac
command.
By the way, the Windows console program I'm using here is ConEmu .
ConEmu official site
Make sure environment variables are set as shown. There are two environment variables required to use JDK, "JAVA_HOME" and "Path".
Make sure that "JAVA_HOME" points to the JDK installation folder and the path to "bin" under the installation folder is appended to top of "Path".
If you manually installed the "ZIP" format modules, set these environment variables manually as well.
Since the Liberica JDK includes JavaFX, there is no need to set the environment variable "PATH_TO_FX" as was required when installing OpenFX separately.
How to check and change Windows system environment variables
Compile and run JavaFX sample program
Open the OpenFX official site, select "Documentation" from the top menu, and click "Getting Started with JavaFX" from the center left of the screen.
OpenFX official site
Distribution site of "HelloFX.java" (github)
javac HelloFX.java
.
Compilation is complete if no error messages are displayed, as shown in this figure.
A class file "HelloFX.class" should have been created in the folder where the source code was saved.
Liberica JDK includes JavaFX, so you don't need to specify
--module-path %PATH_TO_FX% --add-modules javafx.controls
on the command line like you would when installing OpenFX separately.
java HelloFX
from the console to launch the sample program.
A window like this one will open, with the Java and JavaFX versions displayed in the center of the screen.
To solve runtime error 'JavaScript script engine is disabled'
JavaFX allows Java scripts to be written inside FXML files. But since Java version 15, script engine "Nashorn" has been removed. As a result, when you run a Java program that has Java Script inside an FXML file, you will see an error similar to the following:javafx.fxml.LoadException: JavaScript script engine is disabled.
To avoid this, you need to install a separate Java script engine.
Java script engines that are highly compatible with JDK include the following.
How to check and change Windows system environment variables
Select any line and click "Edit" to edit that line. Click "Up" or "Down" to change the position of the line. You can change the priority of items.
If you click "Edit Text", the display will be similar to the "New" screen above. All items can be edited with ";" connected.