我基于此示例在新的 Java SDK 11 中创建了项目:
入口点.java
package com.example;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Label;
public class EntryPoint extends javafx.application.Application {
public static void main (String[] args) {
launch();
}
public void start(Stage stage) {
Label label = new Label("Hello, JavaFX11!");
Scene scene = new Scene(label, 640, 480);
stage.setScene(scene);
stage.show();
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Example</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
</dependencies>
</project>
IntellIJ IDEA 方面没有警告。当我试图编译时,我得到了错误(原件不是英文的,所以它可能与英文原件不同):
Error:(7, 20) java: Can not access to javafx.stage.Stage
Class C:\Users\XXXXX\.m2\repository\org\openjfx\javafx-graphics\11\javafx-graphics-11-win.
jar(javafx/stage/Stage.class) is invalid.
Class/File Version is 54.0; 52.0 is required.
Delete it, or set right directory.
更新
尝试设置 JAVA_HOME 系统变量: