JavaFX模块不会导出到未命名的模块 [英] JavaFX module does not export to unnamed module

查看:81
本文介绍了JavaFX模块不会导出到未命名的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gradle(与Kotlin和TornadoFX)构建JavaFX应用程序.使用下面的gradle构建和IntelliJ,可以正常构建和运行它,但是使用应用程序插件并运行该应用程序,会出现以下错误:

I am building a JavaFX application using gradle (with Kotlin and TornadoFX). Building and running it works fine with the below gradle build and IntelliJ but using the application plugin, and running the application, I get the following error:

Caused by: java.lang.IllegalAccessError: superinterface check failed: class de.codecentric.centerdevice.javafxsvg.SvgImageLoaderFactory (in
 unnamed module @0x591c2277) cannot access class com.sun.javafx.iio.ImageLoaderFactory (in module javafx.graphics) because module javafx.gr
aphics does not export com.sun.javafx.iio to unnamed module @0x591c2277

下面是我的gradle构建脚本.我该怎么解决.

Below is my gradle build script. How can I solve this.

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.50'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

application {
    mainClassName = 'MainKt'
}

javafx {
    version = "13"
    modules = ['javafx.controls', 'javafx.base', 'javafx.graphics']
}

repositories {
    mavenCentral()
    mavenLocal()
    jcenter()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
    maven {
        url "http://4thline.org/m2"
    }
}

dependencies {
    ...
}

tasks.test {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
    }
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

推荐答案

由于我正在使用非模块项目并且依赖JavaFX的模块,所以这是我执行时导致错误的原因

Since I was working with a non-module project and was relying on JavaFX's modules, that is what caused the errors when I executed

> gradle run

我在gradle文件中添加了以下内容:

I appended the following to my gradle file:

run {
    applicationDefaultJvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
                                 '--add-exports=javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
                                 '--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
                                 '--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED',
    ]

    jvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
               '--add-exports=javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
               '--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
               '--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED',
    ]
}

之所以会有"applicationDefaultJvmArgs",是因为应用程序gradle插件使用它来配置jvm参数而不是"jvmArgs".

The reason the "applicationDefaultJvmArgs" is there is due to the fact that the application gradle plugin uses that to configure jvm arguments instead of "jvmArgs".

这篇关于JavaFX模块不会导出到未命名的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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