5

I need to run my Java application on Mac. I could find this tutorial to use Xcode to bundle the application. The tutorial asks readers to have access to Jar Bundle application butI could not find it in the /Developer/Applications/Java Tools/ folder.

After that I came across this answer which seems is offering a good method to do it.

However, I am wondering if there is any better way to get the job done rather than the one mentioned there.

Community
  • 1
  • 1
Jack
  • 6,430
  • 27
  • 80
  • 151
  • 1
    Take a look at [Packaging a Java App for Distribution on a Mac](http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html), [Java Application Bundler](https://java.net/projects/appbundler) and [Take your Java application to the Mac App Store](http://www.intransitione.com/blog/take-java-to-app-store/) for more details – MadProgrammer Jan 07 '15 at 03:45
  • This [example](http://stackoverflow.com/questions/24978212/jar-to-mac-osx-app-bundle-with-app-bundler/24992828#24992828) might also help – MadProgrammer Jan 07 '15 at 03:48
  • 1
    Another useful resource is https://bitbucket.org/infinitekind/appbundler — it contains an Ant task that creates the app bundle for you. What it does not do though, is signing your app, which is a requirements these days for the store. But here [Oracle](http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html#sign) can help. – Hendrik Jan 07 '15 at 10:15
  • Here's a more thorough example of code signing a Java app: http://stackoverflow.com/questions/26938414/code-sign-java-app-for-os-x-gatekeeper/26938545#26938545 – martinez314 Jan 07 '15 at 17:50
  • none of these helped. – Jack Jan 09 '15 at 00:56
  • As of JDK14 you can also use **`jpackage`** see https://stackoverflow.com/a/66511673/191246 – ccpizza Mar 06 '21 at 23:50

2 Answers2

3

The Mac OS X utilities Jar Bundler, Icon Composer, and PacakgeMaker are all deprecated. Even the various AppBundler projects out there seem destine to fade away.

The way forward looks to be javapackager, which is included in the JDK.

The -deploy -native pkg options will convert a Java application (Executable JAR) into a native macOS installer.

Example commands:

$ jar cmf MainClass.txt ShowTime.jar *.class
$ javapackager -deploy -native pkg -srcfiles ShowTime.jar \
   -appclass ShowTime -name ShowTime \
   -outdir deploy -outfile ShowTime -v

Output: deploy/bundles/ShowTime-1.0.pkg

screenshot

I posted a detailed tutorial at:
centerkey.com/mac/java

For better or worse, javapackager bundles the JRE and the resulting .pkg file is over 60MB.

Dem Pilafian
  • 5,625
  • 6
  • 39
  • 67
  • it's possible use javapackager to create an installer to install in addition to java application, some other resources like driver, required by application to work? – Giorgio Nov 17 '15 at 16:43
  • Yes, but I have not tried it. I believe you want to use the `-srcdir` flag to include the folder containing the desired resources. The flag sets the "*Base directory of the files to package.*" Alternatively, you could put the resources in the JAR file before running `javapackager`. – Dem Pilafian Nov 17 '15 at 19:36
0

As Dem says, I user javapackager like this:

Open terminal and go to working folder like cd Desktop/ and type;

javapackager \
> -deploy \
> -title AppTitle \
> -name AppName \
> -appclass your.app.class \
> -native dmg \
> -outdir ~/YourOutputDir \
> -outfile out \
> -srcfiles your.jar