3

I work with Netbeans 11.1 and with JDK 8, but I want to try some feature of JDK 13 and I encountered difficulties.

After installing JDK 13, I added the platform in Netbeans in Tools -> Java Platforms, and in the project's properties I indicated that the Java platform is JDK 13.

I wrote the following Java 13 code, but Netbeans does not recognize it as valid:

public static void main(String[] args) {
    String html = """
<html>
    <body>
        <p class="text">Hello, Text Blocks</p>
    </body>
</html>""";
}

I thank you for telling me what steps I should take to configure the environment to run this code

skomisa
  • 16,436
  • 7
  • 61
  • 102
Alberto
  • 339
  • 4
  • 12

2 Answers2

4

[Minor updates made to the instructions following the formal release of Apache NetBeans 11.2.]

To use the text blocks feature in JDK 13 with NetBeans:

  • Install a beta version of NetBeans 11.2. You can download the zip file for a recent build of 11.2 (at your own risk) from https://builds.apache.org/view/M-R/view/NetBeans/job/netbeans-TLP/job/netbeans/job/release112/30/artifact/dist/
  • Download Apache NetBeans 11.2. (Earlier releases will not work.)
  • On that page click the link for netbeans-11.2-vc1-bin.zip to download it. Unzip the downloaded file to any directory, Install NetBeans 11.2 from the downloaded file, and then start NetBeans 11.2 from .../bin/netbeans.exe
  • Create a trivial Java project using File > New Project... > Java with Ant > Java Application, then edit its main() method by copying/pasting the code from the main() method in the OP.
  • Build the project. In the Output window you will see the error message "text blocks are a preview feature and are disabled by default ... (use --enable-preview to enable text blocks)": enter image description here
  • Now position the mouse cursor over the red circle next to the declaration of String html... and click the mouse. You should see a tooltip, and also a message stating "Enable Preview Feature": enablePreview
  • Hit {enter}. The project will be modified to support text blocks, and the compilation error should be gone.
  • Add a call to System.out.println(html); at the end of the main() method, then run the project. You should see the value of html displayed in the Output window: enter image description here

Notes:

  • Enabling the preview feature appears to make the following changes to your project's properties:
    • Build > Compiling > Additional Compiler Options is set to --enable-preview
    • Run > VM Options is also set to --enable-preview
  • You must use NetBeans 11.2 for this to work, even though you can use JDK 13 with NetBeans 11.1 with no obvious issues.
skomisa
  • 16,436
  • 7
  • 61
  • 102
2

According to this page, NetBeans 11.2 will support Java 13.

The official release of 11.2 should be real soon now. According to the current release schedule page it should happen by October 31st. Apparently, the vote on the final release candidate has passed.

But if you are extra impatient, you don't need an fancy IDE to experiment with Java 13. A text editor and command line tools will work.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 1
    All true, but it's worth noting that when using **javac** and **java** from the command line you must also specify ***--enable-preview*** because support for text blocks is not enabled by default; in JDK 13 the text block is a [preview language feature](https://openjdk.java.net/jeps/12). – skomisa Oct 31 '19 at 03:15