Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a JavaFX application using Gradle

I'm trying to build a relatively simple JavaFX application using Gradle. However, I have no idea how to do it.

I'm relatively new to Gradle, and for simple (non-javafx) project I've successfully used the plugins java and application to build and package libraries and command-line applications.

However, I'm completely stuck when it comes to JavaFX. I've read this article, which suggests using the JavaFX plugin, however I could only find the source code for this plugin, but no documentation on how to actually obtain it an use it (in the article they simply apply it from a remote URL, but that fails on my machine, says I'm not authorized...)

Any clues on how to do this properly?

like image 366
Master_T Avatar asked Jul 13 '15 20:07

Master_T


People also ask

Which method is used to create a JavaFX application?

To create a JavaFX application, you need to instantiate the Application class and implement its abstract method start(). In this method, we will write the code for the JavaFX Application.


2 Answers

Here's an example Gradle JavaFX build on GitHub. Note that according to Bintray, the latest version of the plugin is 8.1.1, so replace the '0.3.0' in the plugin URL with '8.1.1' if you want the latest.

Just to be clear, this is a very unusual way to distribute a Gradle plugin. Most are much easier to incorporate in a build!

Edit: up-to-date fork that works using "apply plugin" https://github.com/FibreFoX/javafx-gradle-plugin

like image 90
Peter Ledbrook Avatar answered Sep 24 '22 00:09

Peter Ledbrook


Here is my example project with OpenJDK 12, JavaFX 12 and Gradle 5.4. It uses the JavaFX Gradle plugin.

  • Opens a JavaFX window with the title "Hello World!"
  • Able to build a working runnable distribution zip file (Windows to be tested)
  • Able to open and run in IntelliJ without additional configuration
  • Able to run from the command line

I hope somebody finds the Github project useful. Feel free to clone it. It is licensed with the Unlicense.

like image 26
Peter Lamberg Avatar answered Sep 24 '22 00:09

Peter Lamberg