0

I'm working on a simple JavaFX project using: Windows, VSCode/PowerShell, Java SDK 17.0.2, JavaFX SDK 17.0.2.

Here is my project structure:

bin/
    snaptools/
        Controller.class
        Main.class
        SnapTransceiver.class
        icon.png
        snaptools.fxml
lib/
    openjfx-17.0.2_windows-x64_bin-sdk/
        ...
    jSerialComm-2.9.1.jar
    snaprotocol-1.0.0.jar
src/
    snaptools/
        Controller.java
        Main.java
        SnapTransceiver.java
        icon.png
        snaptools.fxml

I can compile the project using this command line:

javac -encoding UTF-8 -d bin --class-path "lib/jSerialComm-2.9.1.jar;lib/snaprotocol-1.0.0.jar" --module-path lib/openjfx-17.0.2_windows-x64_bin-sdk/javafx-sdk-17.0.2/lib --add-modules javafx.controls,javafx.fxml src/snaptools/*.java

I can run the program using this command line:

java --class-path "bin;lib/jSerialComm-2.9.1.jar;lib/snaprotocol-1.0.0.jar" --module-path lib/openjfx-17.0.2_windows-x64_bin-sdk/javafx-sdk-17.0.2/lib --add-modules javafx.controls,javafx.fxml snaptools.Main

My project is pretty much done. I just need to package it. Unfortunately, it seems everybody is using Maven/Gradle and IDE-specific tricks (Eclipse, NetBeans, IntelliJ). I don't want to depend on these methods.

What I want:

  • An executable .exe file without installation process (one big file that only executes and preferably extracts nothing).
  • Without using Maven/Gradle (I'll probably put everything in a makefile).
  • Without the need of using a specific IDE (I use VSCode, but I don't want to depend on it either).
  • Can be done by command lines on a regular terminal.
  • Contain everything it needs to execute (user doesn't need to install anything).

Is it possible? Btw, I've also been messing with Launch4j, jpackage, and jlink, but couldn't figure it out.

LucasJ
  • 68
  • 1
  • 9
  • 3
    Maven/Gradle *is* the “makefile” of the Java world. And both of those tools operate independently of the IDE. – Basil Bourque Mar 30 '22 at 03:18
  • Use [warp](https://github.com/dgiagio/warp) to create your exe from a [jlink image](https://www.baeldung.com/jlink). There is a demo in [How to create a standalone .exe in Java (that runs without an installer and a JRE)](https://stackoverflow.com/questions/69811401/how-to-create-a-standalone-exe-in-java-that-runs-without-an-installer-and-a-jr). Replace the maven portions of that answer with whatever you want if you don't want to use maven. – jewelsea Mar 30 '22 at 06:01
  • I noted that you use some non-modular jars on the classpath, which won't work with jlink. You can research methods to address that if you wish (which are pretty ugly and I don't have a specific recommendation for). – jewelsea Mar 30 '22 at 06:31
  • 2
    I am wondering whether it actually makes sense to help people making progress which are obviously on the wrong track anyway. They'll just have a longer way back. – mipa Mar 30 '22 at 10:17
  • @BasilBourque yeah I know, I just wanted to stick with the good old make because I'm a C programmer... – LucasJ Mar 30 '22 at 23:38
  • @jewelsea thank you, very interesting solution... that "modular" concept of java is kinda strange, I'll try to learn more about it. – LucasJ Mar 30 '22 at 23:49
  • @LucasJ See Wikipedia, [*Java Platform Module System*](https://en.wikipedia.org/wiki/Java_Platform_Module_System). JPMS was bolted onto Java only relatively recently, Java 9 in 2017. In contrast, Java has always had its package naming and the [Classpath](https://en.wikipedia.org/wiki/Classpath). The main purpose of JPMS is to modularize the Java platform to enable what you are trying to do, build a standalone app that includes only the parts you need/use. JPMS works hand-in-hand with [*jlink*](https://openjdk.java.net/jeps/282) and [*jpackage*](https://openjdk.java.net/jeps/392) tooling. – Basil Bourque Mar 30 '22 at 23:54
  • @mipa I just want to explore all my options and in the end choose one which works best for me, even if it's not 100% what I wanted in the beginning. Btw exploring non-conventional solutions sometimes gives valuable knowledge. Peace. – LucasJ Mar 31 '22 at 00:06

1 Answers1

0

Apologies if you have already come across it, but you might find it useful to take a look at https://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm

This guide provides basic and advanced information about building, packaging, and deploying your JavaFX application. JavaFX deployment requires no special code in your application and has many other differences from Java deployment. Even if you are an advanced Java developer, it is a good idea to review the Getting Started page.

Martin CR
  • 1,250
  • 13
  • 25