Java Tools Tutorials - Herong's Tutorial Examples - v6.22, by Dr. Herong Yang
"jpackage -t pkg" - Package for macOS
This section provides a tutorial example on how to use 'jpackage -t pkg' command to generate a binary distribution package from Java application JAR file in *.pkg format for macOS computers.
Now let's try to use "jpackage" to create a binary package in *.pkg format for my macOS computer. Note that macOS supports 2 binary distribution package formats, *.pkg and *.dmg.
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 pkg" command.
herong$ jpackage -t pkg -n Hello --main-class Hello -i . --main-jar Hello.jar WARNING: Using incubator modules: jdk.incubator.jpackage herong$ ls -l *.pkg -rw-r--r-- 1 herong staff 45404334 Hello-1.0.pkg
3. Double click on the package name Hello-1.0.pkg 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, 239 files
5. Let's run the installed application, Hello. It works!
herong$ /Applications/Hello.app/Contents/MacOS/Hello Hello world!
Cool. "jpackage -t pkg" command can be used to build a binary distribution package from Java application JAR file in *.pkg 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