ant

How to build a macOS application from a Java Jar file

Table of Contents1 - Background2 - Requirements3 - Building your application4 - Note 1: Font smoothing5 - Note 2: Setting the “application category”6 - The Mac/Java AppBundler7 - More information8 - Summary

In this article I’ll show how to build a macOS application from a Java Jar file. I tested this with Java 1.8 on macOS 10.12.5 (Sierra) on June 29, 2017.

Three assumptions in this process are:

How to set the Java version on Mac OS X (macOS) systems

I don’t remember where I first found this line of code, but if you put it in your Mac OS X ~/.bash_profile file, it’s an easy way to set your Mac Java version:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

I can confirm this works with the Bash shell on Mac OS X 10.10. When I run the java -version command after opening a new Mac Terminal window, the output is 1.8.0_25.

A slightly more difficult way to set your Mac Java version is to look under the /Library/Java/JavaVirtualMachines directory to see which versions are installed, and then manually set the version.

How to use JUnit with Scala

Problem: You want to test your Scala code using JUnit.

Solution

Include the JUnit library in your project, and use it in the same way you’ve used it in Java projects, with a few minor changes.

Assuming you’re using SBT on your project, include JUnit into the project by adding this dependency line to your build.sbt file:

Options to put your Java application name on the Mac menubar

If you don't do anything to your Java application on a Mac OS X system, your Java class name will appear in the Mac menubar. Of course, this isn't a good thing. There are a couple of things you can do to get the name of your Java application on the Mac menu bar, and I'll share all of the ways I know how to do this. I've listed these techniques in order here from "easiest" to "best".

A complete Java Ant MacOS Jarbundler build script

Java Mac application FAQ: Can you share a Java/Mac Ant build script that uses the Jarbundler task to make my Java application look like a native Mac OS X application?

NOTE: This solution is for Mac OS X systems running versions of Java prior to Java 7. If I remember right, it only works on those systems, and therefore only on Mac OS X systems 10.6 and earlier. I'm working on new tutorials for Java 7 and Mac OS X 10.7, 10.8, 10.9, and newer.

A free, complete, Java Mac OS X application

Over the last three days I've created a new Java Swing application for the Mac OS X platform, and today I'm giving away all the source code for this project (free of charge). The complete project includes both (a) all the Java source code and (b) all of the Ant build script code needed to build this application. The end result of the build is what appears to the end user to be a native Mac OS X application.