How to Deploy a Javafx 11 Desktop Application with a Jre

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

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.

How to build a executable JavaFX 11 application

Not a solution without Gradle/Maven but I highly recommend you try using Gradle. Create a new Gradle Project (very easy if you use IntelliJ), and you only need to add dependencies in the build.gradle file. Example of what I use to make a Gradle Project using JavaFX :

plugins {
// Apply the application plugin to add support for building a CLI application in java.
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}

repositories {
mavenCentral()
}

dependencies {
// This dependency is used by the application
implementation 'com.google.guava:guava:29.0-jre'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'

// Use JUnit test framework
testCompile('org.junit.jupiter:junit-jupiter-api:5.3.1')
testCompile('org.junit.jupiter:junit-jupiter-engine:5.3.1')

}

run {
standardInput = System.in
}

application {
mainClass = "com.Nephty.main"
}

javafx {
version = "15.0.1"
modules = [ 'javafx.controls' , 'javafx.fxml' , 'javafx.media' ]
}

Two important points : repositories, application and javafx.

In repositories, you specify the repository from which you want to download the librairies, so you don't have to keep them on your local machine. This helps sharing your program, as another user won't have to download and setup JavaFX himself (this can be impossible for a non tech-savy).

In JavaFX, you specify the modules you want to use and the version.

In application, you specify your main class which will be ran.

Then, you can do a console command : graldew.bat run (with cwd as your project directory) or use the easily accessible task in IntelliJ. After that, you can create a shortcut that will automatically run the console command without needing you to open the console and type everything out. If you are the only who is going to use your application, this is the same as having an executable (if we only care about using the program).

There is an application that helps building executable files for java application. This video explains it.

Hopefully you can find what you're looking for here. If not, don't mind replying so we can try to figure something out.

How to export JavaFX 11 Project into Jar?

You may build this project with Maven from your IDE, including necessary dependencies:

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11.0.2</version>
</dependency>

Bundling JRE 8 and JavaFX application

What might be the most sensible approach to allow us form this JRE/JavaFX bundle?
Which jre should we include that also contains a properly licensed JavaFX runtime?
Should we bundle the jre separate from JavaFX implementation?

Oracle builds have both, but you can't distribute it as a commercial product (technically you can for older versions).

For JRE 8/Java 8 apps-use amazon coretto distro, it comes bundled with both. There are other distros as well, but I would trust Amazon more to keep more current since they are incentivized to keep their cloud customers happy and secure.
https://aws.amazon.com/corretto/

In the longer term, you probably will be forced to upgrade to JRE 11, in which all JREs work the same and JFX is bundled separately for all builds. Either way you can no longer distribute any Oracle builds without paying Oracle.



Related Topics



Leave a reply



Submit