Skip to content

Instantly share code, notes, and snippets.

@dgreen
Last active July 19, 2022 15:24
Show Gist options
  • Save dgreen/0204c6c624623f4399e05e9c7e9dc37a to your computer and use it in GitHub Desktop.
Save dgreen/0204c6c624623f4399e05e9c7e9dc37a to your computer and use it in GitHub Desktop.

Configuring NetBeans to build an App using JDK 17 and JavaFx 17

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 without JavaFX installed.
  1. Create project using the File | New Project menu, choose Java with Maven then Simple JavaFX Maven Archtype (Gluon). a. pick a project name and ensure you use an appropriate GroupId. b. change the version of JavaFX to match the installed one (17) 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 17 to reflect the use of JDK 17.
  3. Above the line (right above the line, add
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.4.0</version>
                <configuration>
                    <source>17</source>
                    <target>17</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