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:

Ant - How to use a date or timestamp in an Ant build script

Summary: An Ant date and timestamp (tstamp) task example.

I was just digging through some Ant build scripts I've created, and I noticed a segment of a build script that first creates a timestamp, and then uses that timestamp in the process of creating a manifest file. (This build script is used for building a Java Swing application.)

Here's the code from my Ant script that does this timestamp magic:

How to compile a Java program with Ant

While I'm digging around through Ant build scripts today, here's a sample Ant target I created that demonstrates how to compile a Java program, while also showing a few other things, including how to exclude your JUnit tests during the compile process.

Deploy only your JSP files with this Ant build task

A lot of times when you're working on a Java web application you only need to deploy your JSP files. This happens, for instance, when you're just editing the JSP files to modify the look and feel of your web application. In cases like this there's no need to rebuild your entire application, deploy it, then restart your application server (Tomcat, Glassfish, JBoss, whatever).

Ant FAQ: Ant replace task examples

Ant replace FAQ: Can you share some examples of the Ant replace task?

I've been sharing a lot of Ant tasks lately, and here's another example, this time some Ant replace task examples.

Ant replace task examples

The Ant build script lines shown below demonstrate how to issue a series of Ant replace commands to replace a token in the file with a variable you want to substitute for that token:

Ant classpath: How to build a classpath variable in an Ant script

Summary: An Ant classpath example.

Here's a quick example showing how I typically build a variable to represent my classpath in an Ant build script.

Our Ant classpath example

This snippet of code below shows how I use the Ant fileset task to  create a variable named class.path by including all jar files from my lib directory using the pattern **/*.jar. This syntax can be read as "Include all files named *.jar in the lib directory and all of its sub-directories".

Unit tests - documentation you can compile

In the category of best practices I have to include my thoughts today on unit tests as a form of "comments/documentation you can compile". Let me explain:

I recently had the experience of (a) working on a small but complicated software development project, (b) leaving that project for six months, and then (c) being asked to work on it again. All I can say it wow -- what a great experience it was to come back to a project that was loaded with unit and code coverage tests.