不支持的 JavaFX 配置:类是从'unnamed module @...'装入的



这个问题看起来很相似,如果不是完全相同的话。在这个问题中,Slaw的第二个建议涉及修复module-info以实现正确的模块管理似乎是合适的。但这到底是什么意思;或者更确切地说,是javafx抱怨我的模块有问题,还是它正在谈论的其他模块有问题?

这是我的module-info.java

module myprogram.main {
requires javafx.controls;
requires javafx.fxml;
requires janino;
requires commons.compiler;
requires org.fxmisc.richtext;
requires wellbehavedfx;
requires zt.process.killer;
requires zt.exec;
exports com.bla.myprogram;
opens com.bla.myprogram to javafx.fxml;
}

jdk: jdk16.0.1 + 9

java -jar .MyProgram.jar

@Override
public void start(Stage primaryStage) throws Exception {
System.out.println("enter start");
...
public static void main(String[] args) {
System.out.println("enter main");
launch();
}
enter main
Aug 04, 2021 1:22:52 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @6203f37a'
enter start

(这是我的gradle。构建(如果有任何意义)

plugins {
id 'java-library'
id 'application'
id 'org.openjfx.javafxplugin' version "0.0.10"
}
group 'com.bla.myprogram'
version '0.3'
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'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
implementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
implementation "org.openjfx:javafx-base:11:${platform}"
implementation "org.openjfx:javafx-graphics:11:${platform}"
implementation "org.openjfx:javafx-controls:11:${platform}"
implementation "org.openjfx:javafx-fxml:11:${platform}"
implementation group: 'org.codehaus.janino', name: 'janino', version: '3.0.7'
implementation group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.6'
implementation group: 'org.fxmisc.wellbehaved', name: 'wellbehavedfx', version: '0.3.3'
implementation group: 'org.zeroturnaround', name: 'zt-process-killer', version: '1.10'
implementation group: 'org.zeroturnaround', name: 'zt-exec', version: '1.12'
}
test {
useJUnitPlatform()
}
javafx {
version = "16"
modules = [ 'javafx.controls', 'javafx.fxml']
}
mainClassName = 'com.bla.myprogram.Main'
jar {
manifest {
attributes "Main-Class": 'com.bla.myprogram.Main'
}
from { (configurations.runtimeClasspath).collect { it.isDirectory() ? it : zipTree(it) } } {
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
task createProperties(dependsOn: processResources) {
doLast {
new File("$buildDir/resources/main/version.properties").withWriter { w ->
Properties p = new Properties()
p['version'] = project.version.toString()
p['name'] = rootProject.name.toString()
p.store w, null
}
}
}
classes {
dependsOn createProperties
}

我想这可能是答案:

将多个模块划分到同一个jar中是不可能的,因为一个jar只能包含一个模块。因此,我认为shade插件通过删除它所使用的依赖项的模块信息文件来解决这个问题,这意味着JavaFX代码将不会作为模块加载,并且您会得到这样的警告。我认为摆脱警告的唯一方法是不使用阴影,而是将JavaFX模块作为单独的jar文件,然后在运行应用程序时将其放在模块路径上。

所以最明显的选择就是忽略警告。Javafx警告似乎很少显示任何有用的信息。但是,如果你将你的应用程序分发给其他用户,你并不总是可以视而不见。

另一个(幼稚的)选项是在启动时重定向错误流。这有点幼稚,因为可能会遗漏一些其他错误。

public void start(Stage primaryStage) throws Exception {
System.setErr(oldErr); // reference to default System.err
...
public static void main(String[] args) {
System.setErr(new PrintStream(new NullOutputStream())); 
launch();
}

另一个选择是使用类似jpackage的东西,而不是创建一个jar。这可能不是一个坏主意,因为每个操作系统的javafx库是不同的。

相关内容

最新更新