Java Tools Tutorials - Herong's Tutorial Examples - v6.24, by Herong Yang
"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
javac - The Java Program Compiler
java - The Java Program Launcher
►jpackage - Binary Package Builder
►"jpackage -t dmg" - Package for macOS
"jpackage -t pkg" - Package for macOS
"jpackage -t msi" - Package for Windows
javadoc - The Java Document Generator
jdeps - The Java Class Dependency Analyzer
jdeprscan - The Java Deprecated API Scanner
jcmd - The JVM Diagnostic Tool
jconsole - Java Monitoring and Management Console
jstat - JVM Statistics Monitoring Tool
jhsdb - The Java HotSpot Debugger
jvisualvm (Java VisualVM) - JVM Visual Tool
javap - The Java Class File Disassembler
keytool - Public Key Certificate Tool
jrunscript - Script Code Shell
native2ascii - Native-to-ASCII Encoding Converter