JDK 11 作为 JAVA_HOME?

huangapple go评论89阅读模式
英文:

JDK 11 as JAVA_HOME?

问题

在运行Eclipse 2020-06下的Codename One应用程序时,JAVA_HOME环境变量是否可以指向JDK 11(例如jdk-11.0.8)? 

还是必须指向JDK 8(例如jdk-1.8.0_241)? 

当我将JDK 11设置为JAVA_HOME并尝试在Eclipse 2020-06下运行Hello World应用程序时,出现以下错误:

构建失败
...[缩略]...\HiWorldPrj\build.xml:106: 无法找到javac编译器;
com.sun.tools.javac.Main不在类路径上。
也许JAVA_HOME没有指向JDK。
当前设置为"C:\Program Files\Java\jre1.8.0_241"


我确定JAVA_HOME指向了JDK 11(因为我可以从命令行中输出它)。

但我认为我之所以会出现这个错误,是因为在JDK 9及以上版本中移除了tool.jar,而com.sun.tools.javac.Main过去常在tools.jar中?
英文:

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?

答案1

得分: 2

是的,您可以使用 JDK 11,但是您的问题似乎是 JAVA_HOME 设置为了 JRE 而不是 JDK。

请检查这个答案。仅有 JRE 不能编译 Java 代码。

也许 JAVA_HOME 没有指向 JDK。
它当前设置为 "C:\Program Files\Java\jre1.8.0_241"

找到您的 JDK 11 目录,并将 JAVA_HOME 环境变量设置为该路径。

但是我建议您在 Eclipse 配置选项卡中设置 Java。您可以在 "Windows 菜单 -> Java -> Installed JREs" 找到它。

更新 1

看起来 Codename One 使用了 JAVA_HOME,它在 build.xml 中进行了设置。所以暂时忘记我关于 Eclipse 变量的建议吧。

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

确保您的环境变量 JAVA_HOME 设置为 JDK 11。您可以在这里了解如何设置。

更新 2

另外,您还需要将 build.xml 文件中的每个 source="1.5"target="1.5" 更新为 1.811

eclipse.ini 中更改的示例:

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

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 &quot;C:\Program Files\Java\jre1.8.0_241&quot;

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.

&lt;property name=&quot;javaHome&quot; value=&quot;${env.JAVA_HOME}&quot;/&gt;

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=&quot;1.5&quot; and target=&quot;1.5&quot; 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

答案2

得分: 1

您的JAVA_HOME指向了JRE,而JRE不包含javac Java编译器。

您需要将JAVA_HOME环境变量指向JDK,即Java二进制文件的根目录。

如果您的控制台在您回显JAVA_HOME时显示了JDK 11的地址,那么您的集成开发环境(IDE)可能配置为在您使用该IDE时将该变量覆盖为JRE目录。

或者,您的IDE可以使用其捆绑的JRE,而您的系统可能在引用另一个Java二进制文件(在您的情况下是JDK)。

英文:

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).

huangapple
  • 本文由 发表于 2020年8月23日 07:57:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63542168.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定