0

I am trying to package my JavaFX application into an executable fat JAR, but it never works. I have tried several guides found online including aswers here on SO but I had no luck. I can manage to set the main class correctly, but the class path is always missing, which then throws an error that JavaFx runtime components are missing. I am now using maven-shade-plugin (I have tried other plugins) and here is the configuration in pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.sjsm.App</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

Edit: as requested in the comments I am adding 3 links I used and none of them worked. Also note I have tried other sources than these over the past 2 or so weeks.

link1 link2 link3

  • (1) google: "javafx package maven" (2) click first hit: https://openjfx.io/openjfx-docs/maven – Janez Kuhar Oct 02 '21 at 17:01
  • That is about creating a JavaFX project with Maven and then running it, not about packaging it into an executable jar. – TurgonTheKingOfGondolin Oct 02 '21 at 17:36
  • Well, there's a link to the `javafx-maven-plugin` GitHub repo. [There](https://github.com/openjfx/javafx-maven-plugin#javafxjlink-options) are some instructions on how to create an executable. – Janez Kuhar Oct 02 '21 at 17:43
  • Perhaps it is worth mentioning that you no longer want to build JARs but rather full fledged *launchers* that include a copy of the Java runtime and all the JavaFX libraries along with your code. – Janez Kuhar Oct 02 '21 at 17:49
  • Yes, instructions to ```jlink``` the application, not to create an executable jar, or am I missing somthing? Also what would be the advantage of creating an application with ```jlink``` compared to creating a ```fat jar``` other than having a fully contained application? But that's getting off topic. – TurgonTheKingOfGondolin Oct 02 '21 at 18:18
  • Having a fully contained application is the advantage, and it makes deploying JavaFX applications much easier. See `jpackage`. Regardless, technically JavaFX does not support being loaded from the class-path (implicitly since JavaFX 9, explicitly since JavaFX 16), and that's what's happening when you launch a fat JAR file. But if you insist on placing JavaFX on the class-path instead of the module-path, then note your main class _cannot_ be an implementation of `Application`. You'll have to create a separate main class that simply launches the JavaFX app. – Slaw Oct 02 '21 at 19:47
  • Thank you, I will try that, otherwise I will just ```jlink``` the application as recommended. – TurgonTheKingOfGondolin Oct 02 '21 at 20:22
  • Forget about "I will just jlink the application" unless your application and all of its direct and indirect dependencies are fully modular. Jlink alone cannot handle anything that is not modular. – mipa Oct 03 '21 at 09:09
  • @jewelsea Yes, it is a duplicate. I have not found that question since I did not know the problem was in trying to fat-jar a JavaFX application. I will also look into other options suggested there. – TurgonTheKingOfGondolin Oct 03 '21 at 13:21

0 Answers0