我在 IntelliJ IDEA 2018 中创建了 JavaFX 项目。我已经安装了 Java JDK 11,我的项目 (Maven) 包括所有需要的依赖项:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
</dependencies>
但是当我尝试启动应用程序时,我得到:
Error:(3, 26) java: cannot access javafx.application.Application
bad class file: C:\Users\Baterka\.m2\repository\org\openjfx\javafx-graphics\11\javafx-graphics-11-win.jar(javafx/application/Application.class)
class file has wrong version 54.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
问题出在哪里?什么是版本 54 和 52?新的 Java 11 是否支持 JavaFX?
最佳答案
尝试将其添加到您的 pom.xml 文件中。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11.0.1</source>
<target>11.0.1</target>
</configuration>
</plugin>
</plugins>
</build>
如果您也更新所有 Maven 插件会更好。看到这个 youtube link ,这就是我得到配置的地方。
关于IntelliJ IDEA 中的 JAVA 11 和 JavaFX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52933987/