Using the tool is fairly straight forward, it's what I use to package Mouslr, this is the command that I use after I've built all my code and built all the artefacts (I use IntelliJ for that purpose).
javapackager command
javapackager -deploy \
-title "Mouslr" \
-name "Mouslr" \
-appclass net.igorkromin.mouslr.Capture \
-native dmg \
-outdir ~/Downloads \
-outfile Mouslr \
-srcdir "out/artifacts/Mouslr_jar"
I run javapackager in deploy mode and specify Mouslr as the title, name and the outfile parameters. The appclass is set to the main class of the application, this is the class with the main() method. I then tell javapackage to build a dmg native package, this is really the only option on OS X. The output directory is set to the Downloads folder and the source directory is set to the location where my jar files are saved.
There are a number of options that can be configured, including a custom Info.plist file, the DMG background image, app name, etc. All of this is set in a number of files that must be saved into the package/macosx directory, which must appear on the classpath to the javapackager tool. The easiest way to do this is to have this directory structure in your project directory and run javapackager from your project directory. In my case, my directory structure looks like this:
Now if you are wondering how you generate the icns files, Info.plist, etc, you need not worry. If you run javapackager and pass -verbose as a command line parameter, it will give you the location of where it saves its default configuration files, which you can simply copy into your project and modify.
javapackager verbose output
Config files are saved to /var/folders/y2/__zvkpb547zg92kgv6rx5m540000gn/T/fxbundler3944182578574287884/macosx. Use them to customize package.
That's all there is to it. I've not done much customisation of my package apart from changing the DMG background, but the options are there. This tool will use the JRE that is the default system JRE i.e. the one that is running when you run the javapackager itself. This can be customised of course, but requires to use the Ant tasks that support this tool. I've not done this yet, but will be investigating this option some time in the future.
After the DMG file is created, it can be opened as usual. The packaged app can be dragged into the Applications folder and launched like any other app.
-i