E
E
Evgeny T.2018-11-07 11:06:18
Java
Evgeny T., 2018-11-07 11:06:18

How to distribute java programs under Windows?

The time is coming and it's time to start giving the program to clients in the form of an executable exe file instead of a batch file with the line java MyCoolApp.
How to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-11-07
@Beshere

A commonly used method is to download launch4j , set it against your jar file and get the executable. In fact, this is a self-extracting archive with a launcher and the original file inside, but this is not visible to the user.
A better way is to use jlink : Simple
project directory structure

src
└───com.example
    │   module-info.java
    │
    └───com
        └───example
                App.java

package com.example;

public class App {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Build Commands
javac -d build\mods\com.example src\com.example\module-info.java src\com.example\com\example\App.java

jar --create --file=build\libs\com.example.jar --main-class=com.example.App -C build\mods\com.example .

jlink --module-path build\mods --add-modules com.example --output build\app\example --launcher start=com.example/com.example.App --compress=2 --no-header-files --no-man-pages --strip-debug

As a result, the example application directory will appear in the build\app directory, which contains the JRE and the program itself in a form ready for distribution. True, the launch is still carried out using a batch file - example\bin\start.bat
Naturally, it is better not to type commands by hand, but to entrust this to the collector - Maven or Gradle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question