JDK 11 as JAVA_HOME?

Viewed 13861

Can the JAVA_HOME environment variable refer to JDK 11 (e.g. jdk-11.0.8) while running Codename One applications under Eclipse 2020-06?

Or does it need to point to JDK 8 (e.g. jdk-1.8.0_241)?

I am having the following error when I try to run Hello World app under Eclipse 2020-06 when JDK 11 is set to JAVA_HOME:

BUILD FAILED
...[shortened for brevity]...\HiWorldPrj\build.xml:106: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre1.8.0_241"

I am positive JAVA_HOME points to JDK 11 (because I can echo it from command line).

But I think I got this error because tool.jar is removed in JDK versions 9 and up and com.sun.tools.javac.Main used to be under tools.jar?

2 Answers

Yes you can use JDK 11 but your problem seems that the JAVA_HOME is set to the JRE and not the JDK.

Check this answer. The JRE alone cannot compile Java code.

Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre1.8.0_241"

Find where your JDK 11 directory is and set the JAVA_HOME environment variable to that path.

However I recommend that you set the Java in the Eclipse configuration tab. You'll find that at "Windows menu -> Java -> Installed JREs".

Update 1

It seems that Codename One uses JAVA_HOME, it is set up in the build.xml. So forget what I said about the Eclipse variables for now.

<property name="javaHome" value="${env.JAVA_HOME}"/>

Make sure your environment variable JAVA_HOME is set to the JDK 11. You can see dos on how to set that here.

Update 2

Also, you'll need to update every source="1.5" and target="1.5" in the build.xml file to either 1.8 or 11.

Example of the change in the eclipse.ini:

-vm
C:/Users/evand/Downloads/openjdk-11.0.2_windows-x64_bin/jdk-11.0.2/bin/javaw.exe

Your JAVA_HOME refers to the JRE, and JRE does not contain javac Java Compiler.

You need to point your JAVA_HOME environment variable to the JDK, i.e. the root directory of the Java binaries.

If your console prints the address of JDK 11 when you echo JAVA_HOME, then it might be that your IDE is configured to override that variable with the JRE directory when you're using that IDE.

Alternatively, your IDE can be using its bundled JRE, and your system might be referring to another Java binaries (JDK, in your case).

Related