Using Netbeans, the default Maven JavaFX/FXML generates Java files that are flagged as having errors

Viewed 158

The problem: Using NetBeans 12.6, OpenJDK 17.0.2, JavaFX 17.0.2 on Windows 10, a project created using “FXML JavaFX Maven Archetype (Gluon)” compiles, builds, and runs without problems, but the source files report “duplicate class” for every class and also complain about missing serialVersionUIDs.

If I introduce other errors, they aren’t flagged in the source (the compiler catches them, though). For example, I removed a required throws clause and no error marker appeared.

If I accept the suggestion to suppress the serialVersionUID warning, the “@SuppressWarnings("serial")” message added is itself flagged as an error (“annotation type not applicable to this kind of declaration”). If I try to rename the class using Refactor / Rename, I get a warning “Cannot refactor this object.”

In short, the source parsing seems screwed up, making a lot of essential Netbeans features unavailable. I have no clue as to how to fix it. Most suggestions I've found are resolved by upgrading Java from 8 to 9 (or something like that). I'm using Java 17, so that's not helpful.

I have a Netbeans Ant JavaFX/FXML project that works fine, so the problem is specific to the Maven project. What I know about Maven would fit in a thimble—I was hoping to start with the simple JavaFX application that Netbeans generates and then try moving my Ant project into a Maven project.


I create the project using Java with Maven / FXML JavaFX Maven Archetype (Gluon). This asked me to enable JavaFX for Windows and the nb-javac plugin:

Choose Project dialog

Enable some additional functionality

After restarting the IDE, I then chose my project. I changed the JavaFX version to 17.0.2 and the javafx-maven-plugin-version to 0.0.8. Here’s the project definition:

The project definition

This image shows the problem. There are error flags for every class. I've hovered over one to display the duplicate class error message (there are no duplicates files).

enter image description here

Here’s the module-info.java file:

module org.freixas.gamma {
    requires javafx.controls;
    requires javafx.fxml;

    opens org.freixas.gamma to javafx.fxml;
}

Here’s the POM file. I added some extra JavaFX dependencies (removing them doesn't change anything):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.freixas</groupId>
    <artifactId>org.freixas.gamma</artifactId>
    <version>alpha</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>17.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>17.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>17.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>17.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>17.0.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <configuration>
                    <mainClass>org.freixas.gamma.App</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                    </execution>
                    <execution>
                        <!-- Configuration for manual attach debugging -->
                        <!-- Usage: mvn clean javafx:run@debug -->
                        <id>debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for automatic IDE debugging -->
                        <id>ide-debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for automatic IDE profiling -->
                        <id>ide-profile</id>
                        <configuration>
                            <options>
                <option>${profiler.jvmargs.arg1}</option>
                <option>${profiler.jvmargs.arg2}</option>
                <option>${profiler.jvmargs.arg3}</option>
                <option>${profiler.jvmargs.arg4}</option>
                <option>${profiler.jvmargs.arg5}</option>
                            </options>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <name>Gamma</name>
    <description>A Minskowski spacetime diagram generator.</description>
</project>
0 Answers
Related