What to do with JavaFX and OpenJFX in Apache NetBeans?

Sunday August 25, 2019

If Apache NetBeans runs on JDK 8, a range of Ant-based JavaFX sample applications are available in NetBeans to help you get started and learn about JavaFX. However, if NetBeans does not run on JDK 8, the available Ant-based JavaFX samples don’t work (can’t be created) but there’s no point in working on fixing that since from JDK 11 onwards JavaFX is no longer part of the JDK and Maven/Gradle-based OpenJFX samples are obvious candidates for integration into NetBeans instead.

However, how should that be handled in NetBeans? Before Apache NetBeans 11.1, there was no integration with OpenJFX. Only JavaFX projects and samples were built into NetBeans, which led to a great deal of confusion since when someone sets up an environment from scratch today, they’re unlikely to have installed JDK 8. Much more likely, they’ll have JDK 11 or 12 and then those JavaFX projects and samples in NetBeans cannot be used, i.e., when you try to create those samples, while running NetBeans on anything other than JDK 8, you’re simply told in the wizard that you have the wrong JDK. And then you somehow need to find out that the best thing to do next is use the OpenJFX documentation to set up the OpenJFX samples in NetBeans.

That is suboptimal and so Gluon integrated their two sample applications into Apache NetBeans 11.1, i.e., in the most recent release:

That is a step forward but still suboptimal, as explained here by Jaroslav Tulach:

That entire new module is not needed. Literally, all that needs to be done is that this file needs to be updated with two new template registrations:

And, literally, this is all that needs to be added there, since the two OpenJFX samples are on Maven Central and as pointed out above, "NetBeans has a nice support for creating wizards over Maven archetypes."

@TemplateRegistration(folder = ArchetypeWizards.TEMPLATE_FOLDER,
position = 925,
displayName = "#LBL_Maven_FXML_Archetype",
iconBase = "org/netbeans/modules/maven/resources/jaricon.png",
description = "javafx.html")
@Messages("LBL_Maven_FXML_Archetype=FXML JavaFX Maven Archetype")
public static WizardDescriptor.InstantiatingIterator<?> openJFXFML() {
    return ArchetypeWizards.definedArchetype("org.openjfx", "javafx-archetype-fxml", "0.0.2", null, LBL_Maven_FXML_Archetype());
}

@TemplateRegistration(folder = ArchetypeWizards.TEMPLATE_FOLDER,
position = 926,
displayName = "#LBL_Maven_Simple_Archetype",
iconBase = "org/netbeans/modules/maven/resources/jaricon.png",
description = "javafx.html")
@Messages("LBL_Maven_Simple_Archetype=Simple JavaFX Maven Archetype")
public static WizardDescriptor.InstantiatingIterator<?> openJFXSimple() {
    return ArchetypeWizards.definedArchetype("org.openjfx", "javafx-archetype-simple", "0.0.2", null, LBL_Maven_Simple_Archetype());
}

That literally is all that is needed to be added to the Java source file above, instead of having a completely new module, which doesn’t integrate as neatly as the above with the Apache NetBeans infrastructure. (And this is a small tip for anyone else wanting to make their Maven archetypes available to NetBeans: the above is literally all you need to do.)

However, the fundamental question remains: how do we notify users of Apache NetBeans that they should be using OpenJFX and not JavaFX? Maybe we should simply remove all JavaFX projects and samples, however that would be unfortunate for anyone using JDK 8. Or maybe the solution is to create a category named "Legacy" in the New Project dialog and then put all JavaFX projects and samples there, so that it’s clear that they’re not recommended, while still having them available for JDK 8 users?