Packaging JavaFX Applications using Gradle

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
about a year ago i made a video about how to make javafx applications using intellij idea and gradle with the javafx plugin that video has been pretty popular and it's a technique i use all the time in my own work and with my students however several people have asked well how do we package the applications and up until recently i didn't have a real good answer to that and honestly i don't think there was a real good answer to that recently though i've looked more into it and i have a solution that works pretty well for me and i'd like to share it with you today so let's start by looking at this application that was created using the technique i showed before this is a simple javafx application and in my build.gradle file i've brought in the application plugin and the javafx plugin i've specified the main class name as a configuration for the application plugin and i've told the javafx plugin that i need the javafx controls module so that should allow us then to via gradle run the application and sure enough there it is okay so let's say we want to package this and give it to people to install and run on their own computers well there's a couple of steps involved the first thing i'm going to do is actually change the version of gradle because this technique that i'm going to show you doesn't work on the latest release of gradle so i'm going to go over to my gradle folder here and choose gradle wrapper properties and change this down to six five now again you know these things might change depending on when you watch the video but as of this recording this is a required downgrade so change that refresh gradle that's good now my next step is going to be to bring in a new plugin so let's get back over here and the plugin i want is called the badass j-link plug-in and it looks like this that's the most recent version as of this recording we can go ahead and reload that okay so another piece we're going to need here is to actually define our application as a module and not just as a old-fashioned java application now you may notice that i used to use edu.bsu.cs222 as a lot of my package names but it turns out modules aren't supposed to have numbers at the end of their package identifiers and so i'm trying to break that old habit and get into a new one and just call it edu.bsu.cs now if i right-click over here and say new one of the options that come up here is a module info.java that's exactly what i want so i'll select that i'll go ahead and add that to git because i always have version control under me okay so what do we need to do here well we need to tell it what the name of our module is and the conventional name is just whatever package you are making your application in so here i'm going to change this to edu oops mediu.bsu.cs and we have to tell it what dependencies this particular module has now my main application remember is using controls from javafx so we're going to go over here and say that we require the javafx dot controls module and we have to say what module we are exporting from here and so we can say this exports edu.bsu.cs and that should be all we need here let's get back to the build.gradle file now in order for this to package correctly we have to tell the application plugin what module we're using so we do that like this main module is a property so we have to call set on it and that'll be just edu.bsu.cs again all right we're almost there now we can notice that this jlink plugin gives us extra options here under build the one i care about right here is jpackage if i double click on this it's going to run that jpackage target and that's actually going to fail here because i'm running on ubuntu linux which doesn't support rpm so i can add some extra configuration here and it looks like this this tells my system to use deb as the installer type so let's go ahead and just run that one more time notice we get some warnings here about using incubator modules that's because some of these features we're using are subject to change with the next stable release of java but they do work for now okay that finished let's see what it actually did i'm going to go into this build folder we can see there's a folder here called j package for convenience i'm going to open that up in dolphin which is my file explorer so let's look in here and we can see that there is a deb file this is an installer for linux and in here this is actually what it packaged up if i go into the bin folder and this is executable i can just double click it say run it and yeah that's my application running outside of the ide so that works fine if you're on linux if you're on windows what you're going to want to do is well not tell it to build a dev file because i don't know how to do that you're also going to need to grab the wix toolset so you go over to wixtoolset.org and install that on your operating system and then on windows you should be fine by the way wix here is a free and open source and so you know there's no trouble with using this if you're on a mac you can just brave to the intersection of st jobs and i'm sure some magic will happen and you'll be fine so that's how i've been able to take my javafx applications and create installers and native executables for them i hope you found that useful happy programming
Info
Channel: Paul Gestwicki
Views: 1,521
Rating: undefined out of 5
Keywords:
Id: dLH-HjiCtaI
Channel Id: undefined
Length: 5min 33sec (333 seconds)
Published: Wed Apr 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.