Search code examples
javacodenameone

JDK 11 as JAVA_HOME?


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?


Solution

  • 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