Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a standalone application using JavaFX 11 (Modular)? [duplicate]

I'm following the tutorial here and using openjdk 11.0.2 and javafx-sdk-11.0.2.
I've imported the maven project in Eclipse. The project actually compiles and packages just fine. It also created the jar file in /target directory.
The problem is, I want to export a single executable for my application which also embeds the necessary JRE in itself (so there would be no need to have a JRE installed on the target machine).
Here is the actual project .

How can I automate the generation of the standalone executable in maven? I want a single exe if possible.

like image 546
Zeta.Investigator Avatar asked Mar 16 '19 11:03

Zeta.Investigator


1 Answers

Studying other questions here on SO, I think there is no way to produce a single EXE that includes the JRE. However, the tools mentioned can produce an EXE that can be put alongside a "jre" directory.

Using the JavaPackager Maven plugin, this can actually be achieved quite easily, simply by adding something like this in your POM:

<plugin>
    <groupId>io.github.fvarrui</groupId>
    <artifactId>javapackager</artifactId>
    <version>1.6.2</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>package</goal>
            </goals>
            <configuration>
                <mainClass>...</mainClass>
                <bundleJre>true</bundleJre>
                <platform>windows</platform>
            </configuration>
        </execution>
    </executions>
</plugin>

Running mvn package will generate a directory inside "target" that contains the EXE, a "jre" directory and a "libs" directory. The plugin can also generate an installer file.

Obviously, for different platforms you need to adjust the config, but I tested this on Windows with JDK 16 and 17, and it seems to work fine.

like image 104
rolve Avatar answered Oct 13 '22 17:10

rolve