Skip to content

Instantly share code, notes, and snippets.

@dgreen
Last active July 19, 2022 14:12
Show Gist options
  • Save dgreen/5b9d41c7f555743143024e1d998662f3 to your computer and use it in GitHub Desktop.
Save dgreen/5b9d41c7f555743143024e1d998662f3 to your computer and use it in GitHub Desktop.
Netbeans 12.4 and JavaFX App Development

Configuring NetBeans to build an App using JDK 15 and JavaFx 16

This is a short note to document a process for creating a build environment in NetBeans to

  • Build a modular project with JavaFx
  • Run project inside NetBeans environment with the Run Project key (or from menu)
  • Debug project inside NetBeans environment with the Debug Project key (or from menu)
  • Extract Javadoc documentation from the project with the Run | Generate Javadoc menu
  • Execute the code from the command line on a machine with the Azul JDK with JavaFX installed.
  1. Create project using the File | New Project menu, choose Java with Maven then Project from Archetype and then find the javafx-archetype-simple-netbeans (or javafx-archetype-fxml-netbeans), a. pick a project name and ensure you use an appropriate GroupId. b. change the version of JavaFX to match the installed one (16) c. consider changing the Debug property to "Y" if you wish to use Debug | Debug Project.
  2. Go to the Project tab on the left, and find the group Project Files under the new project. Open the pom.xml file and update lines 9 and 10 from 11 to 15 to reflect the use of JDK 15.
  3. Above the line (right above the line, add
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <source>15</source>
                    <target>15</target>
                    <sourceFileExcludes>**/module-info.java</sourceFileExcludes>
                </configuration>
            </plugin>

to allow for Javadoc generation via NetBeans Run > Generate Javadoc (project).

  1. Hit Save
  2. Set this project to be the main project by right-clicking on the project name and choosing Set as Main Project.
  3. Select Run | Clean & Build. You may have to do this twice to resolve errors.
  4. Hit Run. Program should run and display a window with a bit of information. Close the window.
  5. Set a breakpoint on line 19 (var label = ...) in App.java. Choose Debug | Debug Main Project. It should stop at the breakpoint. Hit continue and you should see the program window. Close it. Clear the breakpoint.
  6. Choose Run | Generate Javadoc. Choose File tab in the upper left and go to target/site/apidocs/ and select index.html and right-click View. You should see an index of the project.
  7. Go to the NetBeansProject directory (or wherever you are putting your projects. In the command line either in the Operating system or NetBean's terminal, change to the target directory.
java -cp yourproject-1.0-SNAPSHOT.jar yourpackage.yourproject.App  # or whatever is the class with main

Note 1: NetBeans will modify the pom.xml file when you choose to use a test framework.

Note 2: with additional effort, you can package things such that everything needed to run is contained in your collection. One can build an installer for the program, package it for the OS in more standard form, or embed more into the .jar file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment