Maybe you’ve run into a similar situation as me. I’ve taken Java classes at colleges and I’ve also been learning Java on my own free time making applications. When I first learned Java, I started to learn to make GUI applications using Swing. Then I found JavaFX. WOW! Gamechanger! So I spent the time to learn JavaFX and built this sweet program that is actually pretty handy for work. Only one thing, nobody ever taught me how to deploy an application in a format that everyday people could use. In class, I’ve only ever submitted my code files so the teacher could see the code.
But what about when you have a useful application that you actually want people to install and use on their computer?!
This post is part 1 of my discovery on how to create a native package for MacOS for a JavaFX application. I’ve yet to test this on a PC but it should create an exe with this same methodology when compiled on a PC. I’ll post more on this in a separate post.
OK here goes! First off let me set the parameters of how I’m creating this simple Java program:
- I’m using Netbeans, version 8.2
- I’ve created a Maven project (If you haven’t used Maven and are new to Java, I would definitely look into this)
OK so here’s the process:
- In Netbeans, go to File->New Project
- Under the “Maven” category, select the “JavaFX Application” project
- This creates the Maven project folder structure and a default POM.xml
- The POM.xml is the xml file that is used to customize and tell Maven how to build your project. This file can tell Maven, to include other Java libraries, make a Jar or War file, or use Maven plugins (which is what we’ll need to create the native installer)
- Open the POM.xml file under the “Project Files” folder
- Under the “plugins” xml tag, create add this code:
- Now save the project, right click on the main project folder and select Run Maven->Goals
- Now enter the goal as “package” without the quotes and select OK
- This is where the magic happens, and Maven is going to package that JavaFX application into a MacOS application.
- Locate the project folder in your finder. For me it’s located in my home->Netbeans Projects->ProjectFolder->target->jfx->native. That folder should have the .app, .dmg, and .pkg files for your application that can now be run on your computer.