JDK11, use JavaFX in eclipse

Eclipse version Version: 2018-12 (4.10.0)
JDK version 11.0.2
Windows 64

First of all, there is a very detailed description in the official documentation link of JavaFX
. This article does not follow it completely.

General steps:
1. Download an appropriate JavaFX runtime and unzip it to a folder (the location does not need to be fixed but the path must be remembered), for example:
D:\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2"

2. Ecliplse has been downloaded by default, and the development environment of Java 11.0.2 has been configured. Here is an explanation. Note that starting from the Java11 version, JDK and javaFX have been separated (you will find that there is no jre package for javafx after exporting the jre folder using the command line in jdk), so it is not available to download a e(fx)clipseplug-in. , You must manually download and add.

3. Create a User Library according to the official document, and include all the jre under lib in the previously downloaded JavaFX runtime file.
Eclipse -> Window -> Preferences -> Java -> Build Path -> User Libraries -> New
Next, you can name it at will. When you create the project, you can find the FX lib you added in the Library.

4. To create a java project, you need three files ( links to other people's github projects ), and import a custom Library path.

5. The following problem occurs during runtime. The official document mentions the solution, which is to add VM parameters and
Run -> Run Configurations...select Main.java, which is where the main class is located. Click the Arguments tab to see the options for VM Arguments, and add the following parameters
--module-path "\path\to\javafx-sdk-11\lib" --add-modules javafx.controls,javafx.fxml

Here the \path\to\javafx-sdk-11\lib parameter is the path where the openjfx file downloaded before is decompressed, for example
--module-path "D:\eclipse\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml

Run successfully

Question 1: The import javafx cannot be resolved

问题二、Error: JavaFX runtime components are missing, and are required to run this application

Problem three, error: unable to initialize the main class application.Main

As for question 1, it is probably that when the Java11 version of JDK and javaFX were not considered at the beginning, the
problem of running JavaFX by installing the plug-in was caused by the third problem, the probability is because of the problem with the import of the Library package, check the path or go directly to the path Look for these jre files inside.
JavaFX runtime unzip file

Guess you like

Origin blog.csdn.net/Sky_Coolssy/article/details/90113638