javanetbeanspreview-featurenetbeans-12

How to run a single Java file with preview features enabled in Netbeans 12?


I have created a Java Maven project with Java version 14 in Netbeans. I have already instructed the compiler to enable preview features, and that works.

Now I have a bunch of classes containing main methods, and I want to execute one of them using right-click on file » Run File. But I get a java.lang.UnsupportedClassVersionError saying that "Preview features are not enabled". How can I execute the Run File action with preview features enabled?


Solution

  • This can be configured within the project properties.

    1. Right-click on the project and select Properties.
    2. Select Actions in the left menu.
    3. A list of actions is presented. Select Run file via main().
    4. Edit the exec.args property by adding --enable-preview immediately behind the equals sign.