2

Is there a way to get Eclipse to understand Java 13 features, such as text blocks? Eclipse reports errors for the following code:

class Main {
    private String text = """
            first line
            second line
            third line
            """;
}

Errors include:

first cannot be resolved to a type
Duplicate field Main.line

I suspect the problem is the combination of Eclipse and Java 13 in general.

Building with Maven succeeds (with appropriate --enable-preview config). The "installed JRE" in use is Java 13 (with --enable-preview as default VM argument). Installing Java 13 Support for Eclipse 2019-09 doesn't seem to help either (doesn't add the Java 13 compliance level option).

ernest_k
  • 44,416
  • 5
  • 53
  • 99

2 Answers2

8

You would need to set JRE13 to eclipse and also will need to select BETA 13 under settings.

Check configuration steps at https://wiki.eclipse.org/Java13/Examples

In Project > Properies: Java Compiler make sure Java 13 preview features are enabled:

enter image description here

I did follow the steps and it worked for me.

Screenshots from MacOS

enter image description here

enter image description here

www.hybriscx.com
  • 1,129
  • 4
  • 22
  • Thanks. I suppose my problem is that the Java 13 compliance level option is missing. Not sure what I'm missing (can only see up to 12 even with that plugin). Did you also install that *Java 13 Support for Eclipse 2019-09* from the marketplace/update site? – ernest_k Oct 29 '19 at 14:23
  • 1
    Yes I did. A couple of things to remember. I had compatible version Eclipse 2019-09 (4.13). And later I had to set JRE as prerequisite Use Window -> Preferences-> Java -> Installed JREs -> Add... – www.hybriscx.com Oct 29 '19 at 15:00
  • 2
    @ernest_k If the Java 13 compliance level option is missing, the _Java 13 Support for Eclipse 2019-09_ plug-in has not (correctly) be installed (a configured Java 13 JRE/JDK is only required to run your application, not to compile it as Eclipse has its own compiler). What do you get when you try to install _Java 13 Support for Eclipse 2019-09_ again? – howlger Oct 29 '19 at 17:13
  • @howlger sorry for delayed response. Every time I install it, Eclipse takes it (there's always something it installs from the same update site), yet the Java 13 compliance level option doesn't show. I've installed it maybe a dozen times by now :) – ernest_k Oct 30 '19 at 15:29
  • Hi @ernest_k, I will try to uninstall and install it again to see if I face this problem. Can you please confirm the exact version of eclipse you are using? – www.hybriscx.com Nov 01 '19 at 02:48
  • @www.hybriscx.com The 'About' box says `Version: 2019-09 R (4.13.0), Build id: 20190917-1200`. I'm on Linux. – ernest_k Nov 01 '19 at 04:53
  • Hi @ernest_k - Apologies for late reply. I wasn't having access to my laptop in last couple of days. I tried it again on my MacOS and its working perfectly. Adding a couple of images from this morning to my answer. Please check. – www.hybriscx.com Nov 04 '19 at 02:25
2

Perhaps because I am using Cucumber for Eclipse, in addition to the steps given by @www.hybriscx.com, I had to make jdk-13 my selected JRE.

Image of Preferences -> Java -> Installed JREs page

Then I had to Edit that JDK-13 Installation to include the --enable-preview argument.

Image of Edit JRE page

I also set the Execution Environments page to set JavaSE-13 to use the jdk-13 JRE.

Image of Preferences -> Java -> Installed JREs -> Execution Environments

cowang
  • 169
  • 1
  • 1
  • 12
  • Adding the `--enable-preview` flag should not be necessary when you follow the steps above. But you are right, a preview feature only works on a specific VM version, so you can't use Java 13 preview features in Java 14. – Johannes Kuhn May 27 '20 at 19:49
  • Yes, @Johannes Kuhn, I probably only had to do that because I am using Cucumber for Eclipse. I'll bet it does an end run around Eclipse internals and just uses the it to find the compiler and arguments. I've modified my answer to mention Cucumber for Eclipse. – cowang May 27 '20 at 19:59