"jpackage -t dmg" - Package for macOS

This section provides a tutorial example on how to use 'jpackage -t dmg' command to generate a binary distribution package from Java application JAR file in *.dmg format for macOS computers.

As the first test, I want to use "jpackage" to create a binary package in *.dmg format for my macOS computer.

1. Compile and create a JAR file for my Hello.java application.

herong$ javac Hello.java 

herong$ jar -c -f Hello.jar Hello.class  

herong$ ls -l 
-rw-r--r--  1 herong  staff       416 Hello.class
-rw-r--r--  1 herong  staff       736 Hello.jar
-rw-r--r--  1 herong  staff       107 Hello.java

2. Create a binary package in *.dmg format with the "jpackage -t dmg" command.

herong$ jpackage -t dmg -n Hello --main-class Hello -i . --main-jar Hello.jar
  WARNING: Using incubator modules: jdk.incubator.jpackage

herong$ ls -l *.dmg
-rw-r--r--@ 1 herong  staff  50309953 Hello-1.0.dmg

3. Double click on the package name Hello-1.0.dmg to install it on macOS. The entire application will be installed inside /Applications.

4. Verify what's being installed. I see 240 files in 80 directories.

herong$ tree /Applications/Hello.app/Contents/

/Applications/Hello.app/Contents/
|-- Info.plist
|-- MacOS
|   |-- Hello
|-- PkgInfo
|-- Resources
|   |-- Hello.icns
|-- app
|   |-- Hello-1.0.dmg
|   |-- Hello.cfg
|   |-- Hello.class
|   |-- Hello.jar
|   |-- Hello.java
|-- runtime
    |-- Contents
        |-- Home
        |   |-- conf
        |   |   |-- logging.properties
        |   |   |-- management
        |   |   |-- net.properties
        |   |   |-- security
        |   |   |-- sound.properties
        |   |-- legal
...
        |   |-- lib
        |   |   |-- classlist
        |   |   |-- ct.sym
        |   |   |-- libattach.dylib
        |   |   |-- libawt.dylib
        |   |   |-- libawt_lwawt.dylib
...
        |   |-- release
        |-- Info.plist
        |-- MacOS
            |-- libjli.dylib

80 directories, 240 files

5. Let's run the installed application, Hello. It works!

herong$ /Applications/Hello.app/Contents/MacOS/Hello

Hello world!

Cool. "jpackage -t dmg" command can be used to build a binary distribution package from Java application JAR file in *.dmg format for macOS computers.

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

jpackage - Binary Package Builder

 jpackage - What Is It

"jpackage -t dmg" - Package for macOS

 "jpackage -t pkg" - Package for macOS

 "jpackage -t msi" - Package for Windows

 java - The Java Program Launcher

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

 jrunscript - Script Code Shell

 serialver - serialVersionUID Generator

 native2ascii - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 Full Version in PDF/EPUB