首页 > 解决方案 > 无需手动编辑构建路径的 JavaFX 11 设置

问题描述

我想为 JavaFX11 创建一个 gradle 项目。

我已经可以使用 Build Paths 和 VM Arguments 创建和运行 Java FX11 项目。这只是一种解决方法,因为由于运行时版本错误,Gradle 无法编译 JavaFX:

java.lang.UnsupportedClassVersionError: org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Eclipse 版本:2019-03

摇篮版本:5.2.1

操作系统:

Distributor ID:         Ubuntu
Description:            Ubuntu 18.04.1 LTS
Release:                18.04

我已经修复了可能是原因的所有内容:Eclipse 设置:

编译器合规级别 -> 11 已安装 JRE:jdk-11.0.2

Ubuntu Java 设置:

java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

摇篮:

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11.0.2 (Oracle Corporation 11.0.2+9-LTS)
OS:           Linux 4.15.0-47-generic amd64


这是我的 build.gradle:


plugins {

    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.7'
}
def currentOS = org.gradle.internal.os.OperatingSystem.current()
def platform
if (currentOS.isWindows()) {
    platform = 'win'
} else if (currentOS.isLinux()) {
    platform = 'linux'
} else if (currentOS.isMacOsX()) {
     platform = 'mac'
}



dependencies {

    implementation 'com.google.guava:guava:23.0'
    testImplementation 'junit:junit:4.12'

}



repositories {

    jcenter()
    mavenCentral()
}

javafx {
    moduless = ['javafx.controls','javafx.fxml']
    version ='11.0.2'

}

mainClassName = 'de.dom.main.MainApp'




编辑梯度包装器

gradle.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
org.gradle.java.home=/usr/lib/jvm/jdk-11.0.2

编辑问题修复

在项目的根目录中创建一个 gradle.properties,其中包含:

org.gradle.java.home=/usr/lib/jvm/jdk-11.0.2

标签: javaeclipsegradlejava-11

解决方案


推荐阅读