OK here’s part 2 of my blog posts about deploying an application using Maven. The last post showed how to deploy an application for the MacOS. This post will show you how to leverage the Maven use of profiles. In this case the <Profiles> XML tag is used to determine which operating system the application is being built with to determine which bundle settings to use for the packaging phase. Using these settings, if a developer is using a PC to build this program, it will package the program into an MSI installer, on Mac it will package a dmg, and Linux it will package a deb. OK so here’s the code:
- First add the profiles section to the POM.xml. This detects the type of OS and then stores the installation bundle type in the variable called “installer.bundler.” Here’s the section of code for the profiles section:
- In the plugins section, you find a block for the “javafx-mavin-plugin.” This is the plugin that builds the installation bundle. In the configuration section, 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
- Locate the project folder in your finder. On my Mac, it’s located in my home->Netbeans Projects->ProjectFolder->target->jfx->native. That folder should have the .dmg for your application that can now be run on your computer. On my PC, my project is located in My Documents->NetBeansProjects->MavenSample->target->jfx->native. That folder should now have the MSI installer file.
In short, Maven is incredibly powerful in generating installation packages for your Java applications. By using profiles, you can create the installation file for the operation system on which the application is packaged. This creates a more portable project because now, even cross platform, the POM.xml file doesn’t need to be changed.