问题
Error Message: Error: JavaFX runtime components are missing, and are required to run this application
LOOK HERE: project structure photo
I have downloaded the javafx extentions for the project as well as the jar file and attached it, the program knows javafx is there since the code errors went away. However, it then said there were no docs and no it says there's no JavaFx runtime components. I have been hiting error after error trying to get javafx to just run a hello world program in eclipse.
回答1:
JavaFX was removed from Java 11.
It's no longer shipped with the JDK, you need to install it separately (it's now a distinct product called OpenJFX).
回答2:
JavaFX
is no longer provided in the builds after Java 10
; however commercial support for JavaFX in JDK 8 (LTS) will continue through at least 2022.
You can now use OpenJFX Project
, which is the open source home of JavaFX development. It's sponsored by the Swing Group.
回答3:
It's support was removed in Java 11 and it's now a different project. Their documentation specifies how to get started with JavaFX. I am just copy pasting it here because it is very well defined:
Create a Maven project:
- Create a
File -> New -> Project... -> Maven -> Maven project
. The first time you will need to add the JavaFX archetypes: SelectAdd Archetypes...
and type:org.openjfx
for the group id,javafx-archetype-simple
orjavafx-archetype-fxml
for the artifact id, and0.0.1
for the version. - Type
org.openjfx
in the filter field and select the archetype, betweenjavafx-archetype-fxml
orjavafx-archetype-simple
, based on the use of FXML or not in your project. - Provide the groupId, like
org.openjfx
, the artifactId, likehellofx
. You can edit thejavafx-version
property, and set it to 14, and the plugin version to 0.0.4. - When the project opens, select the JDK 14 for the project (
File -> Properties -> Java Build Path -> Libraries
).
- Create a
Verify the pom:
- Edit the pom file, and and verify it has the
javafx.controls
andjavafx.fxml
dependencies and thejavafx-maven-plugin
with themainClass
set tohellofx/org.openjfx.hellofx.App
.
- Edit the pom file, and and verify it has the
Verify the code:
- Edit the
module-info
class. Rename the module tohellofx
. Also, to prevent Eclipse from showing a warning when creating theApplication
class, add also the transitive modules to the file: - Verify the project contains the source code files, like the App main class:
- Edit the
Run the project:
Click
Run -> Run As -> Maven Build -> New launch configuration
to create a new configuration. Name ithellofx
, and add the required goals:clean javafx:run
Run the project
Run -> Run As -> Maven Build -> hellofx -> Run
.In case
JAVA_HOME
is not set to 14, running the project might fail. To avoid it, you can add the correct java command to thejavafx-maven-plugin
:<configuration><executable>/path/to/jdk-12/bin/java</executable></configuration>
.- You can also open a terminal and run
mvn clean javafx:run
to run the project. You might find this exception when running your project:
Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
This is happening running on Windows when Eclipse VM is set to Oracle JDK 1.8 using Maven or Gradle projects. A workaround for this is to edit
eclipse.ini
and change the-vm
option to JDK 14. If that is not possible, another workaround is to add this VM argument to the javafx maven plugin:<configuration> <options> <option>-Djava.library.path=C:\tmp</option> </options> <mainClass>org.openjfx.hellofx.App</mainClass> </configuration>
Maven Repo
来源:https://stackoverflow.com/questions/60512068/java-13-why-are-javafx-runtime-components-missing