我基于这示例在新的Java 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系统变量:

发布于 2018-11-30 18:08:29
以防万一您可以尝试为Stage添加maven依赖项:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
</dependency>

https://stackoverflow.com/questions/52511667
复制相似问题