Back to /

Packaging Java applications #

Since version 16, the JDK distribution has included the jpackage tool, which allows Java applications to be packaged with a bundled JRE. jpackage generates an application launcher for the target operating system, so end users no longer need to install a JRE. All required files are included in the ZIP archive, MSI installer, or DEB package. To keep the application small, developers can customize the bundled JRE distribution and remove modules that the application does not require. With a modern UI layout, Java applications are a good alternative to other cross-platform frameworks like Electron.

Packaging in Maven project #

The Apache Ant plugin executes the jpackage Ant task and creates a new application package in the target directory. A minimal Java application with a trimmed JRE runtime weighs 15 MB.

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <id>build-app-image</id>
            <phase>install</phase>
            <configuration>
                <target>
                    <taskdef name="jpackage" classname="com.archeocs.commons.ant.JPackage" classpathref="maven.plugin.classpath"/>
                    <jpackage
                        name="my-app"
                        appVersion="1.0"
                        input="${project.build.directory}/exec"
                        mainJar="my-app.jar"
                        dest="${project.build.directory}/jpackage"
                    />	
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.archeocs.commons</groupId>
                <artifactId>ant-tasks</artifactId>
                <version>0.9.0</version>
        </dependency>
    </dependencies>
</plugin>