7

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.

rolve
  • 10,083
  • 4
  • 55
  • 75
Zeta.Investigator
  • 911
  • 2
  • 14
  • 31
  • 3
    Have you looked at [How to deploy a JavaFX 11 Desktop application with a JRE](https://stackoverflow.com/q/53453212/9662601)? – Samuel Philipp Mar 17 '19 at 21:46
  • @SamuelPhilipp It seems the tool I need is javapackager but it was removed from JDK 11 and now it is released experimentally – Zeta.Investigator Mar 18 '19 at 10:20
  • Alternatively look at installer generators, creating a setup.exe or such. Also the migration to Java 17 would be easy. – Joop Eggen Nov 22 '21 at 16:47

1 Answers1

1

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.

rolve
  • 10,083
  • 4
  • 55
  • 75
  • 1
    If you really want to create a single standalone EXE it can be done with Gluons tool chain. https://docs.gluonhq.com/#platforms_windows – mipa Nov 22 '21 at 18:20
  • @mipa can the gluons plugin be used to make an installable version of the JavaFX application in windows ? (like JPackage) – Youssef Idraiss Nov 22 '21 at 19:43
  • No, it just creates the EXE but I think you can then create an installer with other tools. I am not so familiar with Windows. – mipa Nov 23 '21 at 08:24