The article discusses building complete distributions for
Windows ,
macOS and
Linux using standard
Java 9 and
10 tools.
It complements the previously published article about
reducing the size of the distribution , focusing not on modularity, but on the peculiarities of creating a distribution for various operating systems.
Lists the changes that occurred with
Java 9 . Describes the sequence of steps performed by the build script, indicating the places where behavior change and customization are possible. There is a story with a happy ending in overcoming features and errors that appeared in
Java 9 .
')

Prologue
Desktop applications written in the
Java programming
language still have a right to exist. The most striking example is
IntelliJ IDEA , which
distributions for installation exist for different operating systems.
The
Java Packager command line utility is included in the
JDK for compiling, creating digital signatures and assembling distributions of Java applications. The utility first appeared in
JDK 7 Update 6 . In addition to using the command line, its functions are available as tasks for
Ant . In the documentation, they are referred to as
JavaFX Ant Tasks .
When writing the article were used:
The project can be found
on github . The compilation and build of the distribution is carried out using
Maven . The example project includes three parts (modules in
Maven terminology):
- multiplatform-distribution-client with application code;
- multiplatform-distribution-distrib with distribution file support files;
- multiplatform-distribution-resources with resources for installers.
Build distributive
The table lists the steps in forming the distributions in order. Specially highlighted
in bold are the steps at which the need or desire to change the behavior, appearance or composition of distributions may arise.
Item number | Maven module | Maven Plugin | Phase of the Maven life cycle | Stage |
---|
one | multiplatform-distribution-resources | maven-resources-plugin | process-resources | Substitution of string values in .iss (for Windows ) and .plist (for macOS ) files |
2 | multiplatform-distribution-client | maven-dependency-plugin | generate-sources | Forming the list of dependencies for the manifest |
3 | build-helper-maven-plugin | generate-sources | Replace delimiter in manifest dependency list |
four | maven-compiler-plugin | compile | Compiling code |
five | maven-jar-plugin | package | Creating a .jar file |
6 | maven-dependency-plugin | package | Copying dependencies for distribution |
7 | maven-resources-plugin | package | Copying additional files for distribution |
eight | maven-antrun-plugin | package | - Using graphics and configuration files to build the distribution
- JRE image creation
- Forming distribution for a specific operating system
|
9 | maven-assembly-plugin | package | Generating a .tar.gz distribution file for Linux (only when running on Linux ) |
ten | multiplatform-distribution-distrib | maven-assembly-plugin | package | - Substitution of string values in
.bat files (for Windows ), .sh (for macOS and Linux ) and licenses
- Forming a universal
.zip distribution (without JRE )
|
To create distros on
macOS and
Linux , only
JDK and
Maven are needed. In the
Windows operating system
, you must first install
Inno Setup or
WiX Toolset . The following assumes
Inno Setup is used .
Running compilation and build distribution in
Windows and
macOS :
mvn clean package -P native-deploy
Launching the compilation and build of the distribution in
Linux (in addition, a
tar.gz
archive file is created):
mvn clean package -P native-deploy,tar-gz
Files of the created distribution with the
exe
extension (for
Windows ),
dmg
(for
macOS ) are located in the
multiplatform-distribution-client/target/deploy/native
directory, with the
tar.gz
extension (for
Linux ) - in the
multiplatform-distribution-client/target
directory .
A universal distribution with a
zip
extension, suitable for any operating system and not containing a
JRE , is created in the
multiplatform-distribution-distrib/target
.
Java 9 and 10 features
The long-awaited release of
Java 9 destructively influenced the distributive build script, which previously worked successfully in the previous version of
Java .
First , the
<fx: deploy> task, which forms the
JRE image and creates the distribution, slightly
changed the structure of the directories it uses . The build script has been modified to accommodate this.
Second , when creating distribution installers,
text and graphic resources were no longer loaded , see
JDK-8186683 . The inability to load resources from the
classpath when building a distribution in
Java 9 is compensated by adding a new
dropinResourcesRoot argument. It is recommended to specify the path to the resource directory as the argument value. In the description of the task in the
pom.xml
file
pom.xml
it will look like this:
Thirdly , because of the mistakes made in the implementation of
Java 9, the ability to include in the distribution subfolders with files , for example, the
lib
subdirectory with the library-dependencies of the program,
was lost . The error manifested itself only in
Windows and
macOS . Overcoming this problem turned into a whole detective story and had to stretch for a long time, postponing the publication of the article.
Chronicle of events:
- OpenJFX repository cloned and an error was found.
- An existing JDK-8179033 was found with a description of the same symptoms.
- On the advice of lany (thank you very much), one and two letters were written to the openjfx-dev group, with a suggestion of the changes required to correct the error, and advice on how to verify their correctness.
- Correspondence with the performers JDK-8179033 - I thank Victor Drozdov for his friendly attitude and patience.
- The error was fixed and the fix got into the next build of the preliminary version of Java 10 - jdk-10-ea + 36 .
- Building the distribution from the command line was successful.
- When trying to add jdk-10-ea + 36 to IntelliJ IDEA in the SDK list, an error (unlike previous builds) created IDEA-183920 .
- The commentator IDEA-183920 indicates the cause of the JDK add error — the disappearance of the javah utility in this JDK build , including the presence of which was required for successful identification.
- Exit IntelliJ IDEA 2017.3.2 , in which the identification error JDK 10 is fixed.
- Building the distribution was possible from the development environment too.
Adaptation of the example for own use
- Rename the project's Maven modules, replacing the multiplatform-distribution prefix in the name with something else.
- Rename the
multiplatform-distribution.bat
and multiplatform-distribution.sh
files located in the multiplatform-distribution-distrib module . - Edit in
pom.xml
files:
- names of the renamed Maven modules;
- the names of the directories corresponding to the renamed Maven modules.
- Modify in
assembly.xml
files:
- names of the renamed Maven modules;
- Mention of modified file names for
multiplatform-distribution.bat
and multiplatform-distribution.sh
.
- Modify in the root
pom.xml
file the pom.xml
values named <app. *> Containing:
- full name of the application;
- short name of the application;
- year (-a) copyright;
- application code in file names;
- default application package;
- class name to run the application.
- Add your own code to the multiplatform-distribution-client module.
- Modify the contents of the
license.txt
and readme.txt
in the multiplatform-distribution-client module. - Change the contents of graphic files and their names in the multiplatform-distribution-resources module.
findings
- standard tools JDK 9 and 10, you can build distributions for different operating systems;
- customization of the composition, behavior and type of distributions is relatively simple;
- Java 9 introduced some features that were taken into account when writing this article.
JEP 311: Java Packager API & CLI for creating a new
API and
CLI (command line interface) for
Java Packager recently appeared.
JEP is currently rejected, previously it was planned to make changes in
JDK 10 and
JDK 11 . When resuming activity, this article may be continued in the near future.
For the upcoming March 4 (
JBreak 2018 in Novosibirsk) and April 6-7 (
JPoint 2018 in Moscow) conferences, there is an opportunity to attend presentations on related topics on
Java 9 and future versions of
Java :