TornadoFX未解决的JavaFx [英] TornadoFX unresolved JavaFx

查看:659
本文介绍了TornadoFX未解决的JavaFx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个应该是桌面应用程序的新项目.为此,我选择了Kotlin语言和TornadoFX框架.我已经安装了TornadoFX插件并创建了一个新的T tornadofx-gradle-project. Intellij进行的基本设置成功,但是遇到了问题.当我想运行生成的项目时,它失败了.该项目无法解析Java fx.我已经浏览了网上,却没有找到可以解决该问题的方法.构建失败后收到的错误日志是:

I wanted to create a new project that should be a desktop application. For this purpose, I have selected Kotlin language and TornadoFX framework. I have installed the TornadoFXplugin and created a new Ttornadofx-gradle-project. The base setup made by Intellij was successful but I have encountered a problem. When I wanted to run the generated project it failed. The project cannot resolve the java fx. I have dug through the web and found nothing that would fix the problem. The error log that I receive after the failed build is:

有人遇到同样的问题吗?我该如何摆脱呢?

HAs anyone faces the same issue? How can I get rid of it?

我已经安装了JDK 11并将其设置为构建配置,但仍然收到问题:

I have installed the JDK 11 and set it up to the build config and I still receive the problem:

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

我中间有什么东西错过了吗?

Is there a change that I have missed something in the middle?

推荐答案

您似乎正在使用Java 11或12运行TornadoFX项目.

It looks like you are running the TornadoFX project with Java 11 or 12.

它看起来也像TornadoFX 插件用于Java 1.8,但是它不建议您使用Java 11 +.

It also looks like the TornadoFX plugin is intended for Java 1.8, but it is not advised what to do with Java 11+.

从Java 11开始,JavaFX不再是JDK的一部分.

Since Java 11, JavaFX is no longer part of the JDK.

您可以在此处阅读有关将JavaFX作为第三方依赖项添加到您的项目的所有信息: https://openjfx .io/openjfx-docs/,并且由于您使用的是Gradle,因此本节将对您有所帮助:

You can read all about getting JavaFX as a third party dependency into your project here: https://openjfx.io/openjfx-docs/, and since you are using Gradle, this section will be helpful: https://openjfx.io/openjfx-docs/#gradle.

我刚刚使用JDK 12.0.1安装了Tornado插件,并创建了一个项目.我还更新了gradle-wrapper.properties文件,以使用Gradle 5.3-bin,因为默认4.4不适用于Java 11 +.

I've just installed the Tornado plugin, and created a project, using JDK 12.0.1. I've also updated the gradle-wrapper.properties file to use Gradle 5.3-bin as the default 4.4 doesn't work with Java 11+.

如果我运行它,会得到相同的错误:

If I run it, I get the same errors:

e: /.../src/main/kotlin/com/example/demo/app/Styles.kt: (3, 8): \
Unresolved reference: javafx
e: /.../src/main/kotlin/com/example/demo/app/Styles.kt: (18, 13): \
Cannot access class 'javafx.scene.text.FontWeight'. Check your module classpath for missing or conflicting dependencies
...

基本上,这些错误表明未找到JavaFX. Tornado插件没想到这一点.

Basically these errors indicate that JavaFX is not found. The Tornado plugin wasn't expecting this.

解决方案

有一个简单的解决方案可以实现此目的:将JavaFX gradle插件添加到内部版本中,以便处理JavaFX部分.

There is an easy solution to make this work: add the JavaFX gradle plugin to the build, so it deals with the JavaFX part.

根据插件的存储库,您要做的就是编辑构建.gradle文件并添加:

According to the plugin's repository, all you need to do is edit the build.gradle file and add:

buildscript {
    ext.kotlin_version = "1.2.60"
    ext.tornadofx_version = "1.7.17"
    ext.junit_version = "5.1.0"

    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            setUrl("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.1.0"
// Add JavaFX plugin:
        classpath 'org.openjfx:javafx-plugin:0.0.7'
    }
}

apply plugin: "kotlin"
apply plugin: "application"
apply plugin: "org.junit.platform.gradle.plugin"
// Apply JavaFX plugin:
apply plugin: 'org.openjfx.javafxplugin'

// Add the JavaFX version and required modules:
javafx {
    version = "12.0.1"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}
...

就这样,刷新您的项目,IDE应该可以识别所有JavaFX类.

And this is it, refresh your project, the IDE should recognize all the JavaFX classes.

如果您像这样修改默认的MainView.kt:

If you modify the default MainView.kt like:

class MainView : View("Hello TornadoFX \n with JavaFX " 
        + System.getProperty("javafx.version")) {
    override val root = hbox {
        label(title) {
            addClass(Styles.heading)
        }
    }
}

您应该能够运行它:

这篇关于TornadoFX未解决的JavaFx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆