vakio
vakio

Reputation: 3177

Unsupported JavaFX configuration: classes were loaded from 'unnamed module @...'

This question seems very similar if not exactly the same. In that question, Slaw's 2nd suggestion involving fixing the module-info for correct module management seems appropriate. But what exactly does that mean; or rather, is there something wrong with my module that javafx is complaining about or is it some other module it's talking about?

This is my 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

(and this is my gradle.build if it has any significance)

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
}

Upvotes: 2

Views: 1943

Answers (1)

vakio
vakio

Reputation: 3177

I think this might be the answer:

Shading multiple modules into the same jar is not possible, because a jar can only contain 1 module. So, I suppose the shade plugin resolves that problem by removing the module-info files of the dependencies it's using, which means the JavaFX code will not be loaded as a module, and you get a warning like this. I think the only way to get rid of the warning is to not use shading, but keep the JavaFX modules as separate jar files, that you then put on the module path when running the application.

So the obvious option is just to ignore the warning. Javafx warnings rarely seem to indicate anything useful. But it's not always an option to just look away if you distribute your application to other users.

Another (naive) option is to redirect the error stream at launch. It's a little naive because there might be some other error missed..

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();
}

Another option is to use something like jpackage instead of making a jar. Which might not be such a bad idea anyway, because the javafx libraries are different for each OS.

Upvotes: 1

Related Questions