Convert Java application to Mac OS X app

32,859

Solution 1

Use the Apple Java Extensions and its Guide

The Apple Java Extensions contains a very complete development guide with information on the deployment of Java applications on Mac OS X and the production of application bundles. It also introduces other aspects of the Apple Java Extensions, like the support for integration with the standard Mac OS X UI.

Other references:

Solution 2

There is a library that let's you package your Java app
Packr: https://github.com/libgdx/packr

Packages your JAR, assets and a JVM for distribution on Windows (ZIP), Linux (ZIP) and Mac OS X (.app), adding a native executable file to make it appear like the app is a native app.

It can even minimize the JRE for you.

Solution 3

jar2app

Packr is a great tool, but at the time I found that I wanted something "easier to use", so jar2app was born. I know this is an old question but perhaps other people might find this program easier to use than other alternatives. If they don't, there's a direct reference in the FAQ to other alternatives (such as Packr).

Solution 4

You can use javapackager tool to build the application and wrap it in into an installer, the following commands show how to convert a jar file into a bundle file:

commands

mkdir -p package/macosx
cp Test.icns package/macosx
jdk=$(/usr/libexec/java_home)
$jdk/bin/javapackager -deploy -native dmg \
   -srcfiles Test.jar -appclass package.Test -name Test \
   -outdir deploy -outfile Test -v
cp deploy/bundles/Test-1.0.dmg installer.dmg
ls -l
open installer.dmg

To change the application icon and more info MacJava.

Solution 5

Since some of the links in the accepted answer are no longer available or suitable in 2020, 8 years from the question was asked, I would like to share my findings that I confirmed working today.

There is a tool, javapackager, shipped with java, can package java application on Windows, Linux, macOS for you.

Here is the official manual: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/javapackager.html

(Also there are other helpful tools here: https://docs.oracle.com/javase/8/docs/technotes/tools/ )


For packaging a mac application, I used this command:

javapackager \
    -deploy \
    -native image \
    -srcdir ./csv-encrypt-tool-mac \
    -srcfiles csv-encrypt-tool.jar \
    -srcfiles dict \
    -srcfiles config \
    -srcfiles log \
    -outdir ./dist \
    -outfile csv-encrypt-tool \
    -appclass some.package.CsvEncToolApp \
    -name "csv-encrypt-tool" \
    -title "csv-encrypt-tool" \
    -nosign \
    -v \
    -BjvmOptions=-Xmx4096m \
    -BmainJar=csv-encrypt-tool.jar \
    -Bicon=icon.icns

And this is the explanation:

-deploy \                                       # Assembles the application package for redistribution with sys JRE
-native image \                                 # Build a .app file. If you want a .dmg, use -native dmg
-srcdir ./csv-encrypt-tool-mac \                # directory where my jar and resource files in
-srcfiles csv-encrypt-tool.jar \                # my executable jar, path relative to -srcdir
-srcfiles dict \                                # one of my resource directories, path relative to -srcdir
-srcfiles config \                              # another one of my resource directories, path relative to -srcdir
-srcfiles log \                                 # again, one of my resource directories, path relative to -srcdir
-outdir ./dist \                                # where I want the package to be put
-outfile csv-encrypt-tool \                     # the output file name without extension, the final file (or bundle which is a directory actually) will be csv-encrypt-tool.app
-appclass some.package.CsvEncToolApp \          # the class with main method, which is the entry point of the whole app
-name "csv-encrypt-tool" \                      # the name (not very sure what this is for)
-title "csv-encrypt-tool" \                     # the title (not sure what it is either)
-nosign \                                       # not sign the app since this is just an internal tool, if you want to publish it, signing is necessary
-v \                                            # verbose
-BjvmOptions=-Xmx4096m \                        # I need 4GB max heap size
-BmainJar=csv-encrypt-tool.jar \                # the jar file with main class
-Bicon=icon.icns                                # the icon

After the command is executed, there will be some files and directories created in dist, where I want the package be, and one of the directories is bundles. The application is put in there.

Since I just built an internal tool, there is no need to sign and packaged without other production ready options. You can refer to the official manual for help.

Hope this help others who do not know how to package an application on macOS in 2020, just like me.

Share:
32,859
Barranka
Author by

Barranka

Actuary, finance and risk oriented; musician, amateur programmer... I love mathematics, probability, statistics, numerical methods, music... and whatever challenges the creativity of human mind. Some links I think it's worth to read: "What have you tried?" by Matt Gemmel Need an Answer? Actually, No ... You Need a Question And some useful links for online code editing: SQL fiddle (a good tool to create SQL reproducible examples) Coding ground (online coding tool in various languages) Actuario, orientado a finanzas y riesgos; músico, programador aficionado. Me encantan las matemáticas, probabilidad y estadística, métodos numéricos, música... y cualquier cosa que rete la creatividad de la mente humana.

Updated on April 26, 2021

Comments

  • Barranka
    Barranka about 3 years

    Is there a way to convert a Java application into a Mac OS X executable app?

    I use NetBeans to develop in Java, and I'd like to "pack" the "dist" folder into an app (just for convenience)