我基于this示例在新的Java SDK 11中创建了项目:
EntryPoint.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系统变量:
最佳答案
以防万一,您可以尝试为Stage添加Maven依赖项:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
</dependency>