4

I have a javaFx application developed with:

  • OpenJDK 11
  • NetbeansIDE 10
  • JavaFX 11

Following the javaFX 11 instructions (here) I have created a self contained app.

Unfortunately, to start the app a long command is required. Something like this:

dist/jlink/HelloFX/bin/java -m hellofx/org.openjfx.MainApp

This is not the best option for the end users.

My question is:

  • How can I create an .exe (Windows) and .app (macOS), easy to distribute and start?
  • How can I add an icon for the app (right now the app appears with the classic java cup icon)?

I was not able to find any updated directions for that.

Thank you.

Fab
  • 1,468
  • 1
  • 16
  • 37
  • You could maybe provide a `.bat` resp. a `.sh` file which contains the command. Scripts act as executables too – Lino Jan 15 '19 at 13:13
  • 1
    @Stultuske The self-contained app (via `jlink`) is already platform-specific; it will contain the JavaFX and JDK modules which have platform-specific native code. And I get the impression the Java ecosystem is moving towards self-contained apps wrapped in native executables for deployment. Everything I've seen suggests deploying JavaFX apps these days requires different packages for each target platform. Note that the _Java code_ will still be cross-platform. – Slaw Jan 15 '19 at 13:40
  • @Stultuske: with the procedure I followed I got a jar and a directory with a bunch of different files. This is not easy to distribute, install and run. Moreover, javaFX already requires to include jmods which are platform dependent. – Fab Jan 15 '19 at 15:52
  • @Lino. Unfortunately, I think that is the only option. This means that I have to distribute a jar with a bunch of other files. The .bat or .sh are not exactly user friendly though. – Fab Jan 15 '19 at 15:54
  • Is there any way you may consider using Gradle for your projects? NetBeans 10 has a built-in task to run `jlink`, but not for the (incoming) `jpackage` tool. Doing it with Ant is not really appealing... – José Pereda Jan 15 '19 at 17:43
  • @JoséPereda. I don't like to change my development environment. I prefer to keep it as simple as possible and completely integrated. Anyway, if jpackage can do what I need I will switch to Gradle. I am not able to find any documentation or examples about jpackage though, could you please provide me a pointer? – Fab Jan 16 '19 at 13:34
  • See this [answer](https://stackoverflow.com/a/54065502/3956070). – José Pereda Jan 16 '19 at 13:37

1 Answers1

1

Compile the executable JAR file, and then use a tool to convert it to EXE.

There are few ways of doing that:

Launch4j is one of them

Another option can be Jar2Exe

MIR
  • 31
  • 1
  • 2
  • 1
    Jar2Exe is not free. I have only one app to distribute. Launch4j looks like promising but it's not clear how to manage the jar file and the jre directory which I created with the mentioned procedure. Any clue? – Fab Jan 15 '19 at 15:58
  • You only need to put your executable jar file into "Jar" and set the output file. Then, in the Header section make sure that "GUI" is selected. There are many more options to choose from, but only with the few above you can click the gear icon and get the resultant EXE. – MIR Jan 15 '19 at 16:01
  • Unfortunately, it doesn't work in that way. When I run the exe: "This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted." – Fab Jan 15 '19 at 16:14
  • Make sure that you do not use a bundled JRE, in the JRE tab you can check that. By the way, I can't include anything else, simply because the answer is valid only because the links and pages exist, if the page or program no longer exists you can't take this answer as valid and you need to look for a different program. – MIR Jan 16 '19 at 17:38