1

I'm new at JavaFX and I'm trying to create a fat Jar of a simple program (password generator). With Maven (assembly plugin, shade or dependencies+jar) or Gradle I get it but a warning appears when I launch it from CLI

java -jar <jar_name>.jar

prompt_jar image_info

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

after all the program runs ok with mouse double click.


In the run phase (inside Eclipse) you can eliminate the warning by changing the Maven POM.xml (javafx-maven-plugin - 0.0.8)
<mainClass>org.openjfx.passwordGen.Main</mainClass> in <mainClass>passwordGen/org.openjfx.passwordGen.Main</mainClass>
more generally
<mainClass>"path_to_Main"</mainClass> in <mainClass>module_name/"path_to_Main"</mainClass>

but if you try in Maven (same previously plugins) you will get an error (ClassNotFoundException).
In the manifest file the "Main-Class" will be passwordGen.org.openjfx.passwordGen.Main and it doesn't exist (seem it merge module_name with Main_path):

Manifest -> Main-Class: passwordGen.org.openjfx.passwordGen.Main
Error: Could not find or load main class passwordGen.org.openjfx.passwordGen.Main

The question is, how can I get a fat Jar with all the modules/dependencies (inside) required by JavaFX and eliminate the warning (with Maven, Gradle or Ant Task script)? I have tried jlink method, it works but I don't really like the .bat file to launch the application. My goal is make a single file and simply double click it. There are also JavaFX JMODS file, it is possible use them to achieve the goal?

Hope someone can help me, thanks in advance.

INFO

In the class that extends Application (PasswordMain) I wrote:

System.out.println(Application.class.getModule().getName());
System.out.println(PasswordMain.class.getModule().getName());

and I get

inside Eclipse : javafx.graphics passwordGen


from CLI (with fat Jar): null null


Here what I get as fat Jar inside fat jar

Script

Module-info.java

module passwordGen {
    requires javafx.controls;
    requires javafx.fxml;
    requires transitive javafx.graphics;

    
    opens org.openjfx.passwordGen to javafx.fxml;
    exports org.openjfx.passwordGen;
}

Maven assembly Manifest:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: filippo
Build-Jdk: 17.0.1
Main-Class: org.openjfx.passwordGen2.Main

Maven dependencies+jar Manifest:

Manifest-Version: 1.0
Created-By: Maven JAR Plugin 3.2.2
Build-Jdk-Spec: 17
Class-Path: lib/javafx-controls-17.0.1.jar lib/javafx-controls-17.0.1-wi
 n.jar lib/javafx-fxml-17.0.1.jar lib/javafx-fxml-17.0.1-win.jar lib/jav
 afx-graphics-17.0.1.jar lib/javafx-graphics-17.0.1-win.jar lib/javafx-b
 ase-17.0.1.jar lib/javafx-base-17.0.1-win.jar
Main-Class: org.openjfx.passwordGen.Main

Gradle Manifest with jar script

jar {
    manifest {
        attributes "Main-Class": 'passwordB.Main'
    }

    from { (configurations.runtimeClasspath).collect { it.isDirectory() ? it : zipTree(it) } } {
        exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
        duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    }
}
----------------------------------------
Manifest-Version: 1.0
Main-Class: passwordB.Main
philfs
  • 11
  • 3
  • 1
    Shading the JavaFX modules into a user application jar is not a supported configuration, if you do that you will be warned about it. – jewelsea Feb 03 '22 at 21:44

0 Answers0