简体   繁体   English

Netbeans 无法找到 java

[英]Netbeans unable to locate java

I am setting up a new machine after a long time.很长一段时间后,我正在设置一台新机器。

I installed java using home brew:我使用 home brew 安装了 java:

brew install openjdk

In my .zshrc file I added:在我的 .zshrc 文件中,我添加了:

export PATH="/usr/local/opt/openjdk/bin:$PATH"

Running 'java -version' gives the following output:运行 'java -version' 给出以下输出:

openjdk version "18.0.1.1" 2022-04-22 OpenJDK Runtime Environment Homebrew (build 18.0.1.1+0) OpenJDK 64-Bit Server VM Homebrew (build 18.0.1.1+0, mixed mode, sharing) openjdk 版本 "18.0.1.1" 2022-04-22 OpenJDK Runtime Environment Homebrew (build 18.0.1.1+0) OpenJDK 64-Bit Server VM Homebrew (build 18.0.1.1+0, 混合模式, 共享)

When I try to run the netbeans 13 installer pkg, I get the following message:当我尝试运行 netbeans 13 安装程序 pkg 时,我收到以下消息:

No Java Found NetBeans IDE cannot be installed. No Java Found 无法安装 NetBeans IDE。 This software can be installed with Java 8 or newer.该软件可以安装 Java 8 或更新版本。 Please download and install the latest update of Java 8 from http://www.oracle.com/technetwork/java/javase/downloads/index.html and restart NetBeans installation.请从http://www.oracle.com/technetwork/java/javase/downloads/index.html下载并安装 Java 8 的最新更新,然后重新启动 NetBeans 安装。

I figured maybe I need to set the java home variable.我想也许我需要设置 java home 变量。 But not sure where the correct location is.但不确定正确的位置在哪里。 I tried:我试过了:

export JAVA_HOME=/usr/local/Cellar/openjdk/18.0.1.1/libexec/openjdk.jdk/Contents/Home

But the error is still there.但是错误仍然存​​在。

  1. Have I set my JAVA_HOME variable correctly ?我是否正确设置了我的 JAVA_HOME 变量? How can I make sure that I have set the correct location ?如何确保我设置了正确的位置?

  2. How can I get the Netbeans installer to install ?如何让 Netbeans 安装程序安装? Why does it not see the JDK ?为什么看不到JDK?

EDIT:编辑:

If I run the following command:如果我运行以下命令:

/usr/libexec/java_home /usr/libexec/java_home

Then I get the output:然后我得到输出:

The operation couldn't be completed.操作无法完成。 Unable to locate a Java Runtime.找不到 Java 运行时。 Please visit http://www.java.com for information on installing Java.有关安装 Java 的信息,请访问http://www.java.com

This is because I installed java via homebrew and did not see this message output in the end:这是因为我通过 homebrew 安装了 java,最后没有看到这个消息输出:

For the system Java wrappers to find this JDK, symlink it with sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk要让系统 Java 包装器找到此 JDK,请使用 sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk 对其进行符号链接

Run the command above to create the symlink, then netbeans installation proceeds.运行上面的命令来创建符号链接,然后 netbeans 安装继续。 Wasn't necessary to set path or home.没有必要设置路径或主页。 Set cpp flags because cpp is cool.设置 cpp 标志,因为 cpp 很酷。

Even for other versions such as 11 it may be necessary to run a similar command.即使对于其他版本,例如 11,也可能需要运行类似的命令。 Homebrew mentions it, but unless you're paying attention may not notice it at the end of the installation. Homebrew 提到了它,但除非你注意,否则在安装结束时可能不会注意到它。

I suspect the problem is that the NetBeans 13 installer does not support the use of JDK 18, because NetBeans 13 itself does not officially support JDK 18. From the Release Notes (with my emphasis added):我怀疑问题在于 NetBeans 13 安装程序不支持使用 JDK 18,因为 NetBeans 13 本身并不正式支持 JDK 18。来自发行说明(我的重点已添加):

The Apache NetBeans 13 binary releases require JDK 11+, and officially support running on JDK 11 and JDK 17 . Apache NetBeans 13 二进制版本需要 JDK 11+,并正式支持在 JDK 11 和 JDK 17 上运行

Also, note that:另外,请注意:

  • NetBeans 13 was released on March 4, 2022. NetBeans 13 于 2022 年 3 月 4 日发布。
  • JDK 18 was released 18 days later, on March 22, 2022. JDK 18 于 18 天后,即 2022 年 3 月 22 日发布。

So while NetBeans 13 may appear to run fine with JDK 18, it seems probable that the installer does not support the use of JDK 18, which didn't even exist when the installer was released.因此,虽然 NetBeans 13 可能在 JDK 18 上运行良好,但安装程序似乎不支持使用 JDK 18,而在发布安装程序时甚至不存在。 Unfortunately the installer is providing a very poor error message when you attempt that:不幸的是,当您尝试执行以下操作时,安装程​​序会提供非常糟糕的错误消息:

No Java Found NetBeans IDE cannot be installed. No Java Found 无法安装 NetBeans IDE。 This software can be installed with Java 8 or newer.该软件可以安装 Java 8 或更新版本。 Please download and install the latest update of Java 8 from http://www.oracle.com/technetwork/java/javase/downloads/index.html and restart NetBeans installation.请从http://www.oracle.com/technetwork/java/javase/downloads/index.html下载并安装 Java 8 的最新更新,然后重新启动 NetBeans 安装。

The installer's error message is highly misleading for two reasons:安装程序的错误消息具有高度误导性,原因有两个:

  • Instead of "No Java Found" it would be more accurate if the error was "No supported version of Java found" .如果错误是"No supported version of Java found" ,而不是"No Java Found"会更准确。
  • The advice "Please download and install the latest update of Java 8" makes no sense because NetBeans 13 doesn't even support the use of JDK 8. “请下载并安装 Java 8 的最新更新”的建议毫无意义,因为 NetBeans 13 甚至不支持使用 JDK 8。

So this looks like an issue with the NetBeans Installer rather than NetBeans or Java 18. You have a couple of workarounds:所以这看起来像是 NetBeans 安装程序而不是 NetBeans 或 Java 18 的问题。您有几个解决方法:

  • Run the installer using JDK 17 instead of JDK 18. Once you have NetBeans installed and running on JDK 17, you can then add JDK 18 as a second Java Platform, or edit netbeans.conf so that NetBeans will use JDK 18 instead of JDK 17 after a restart.使用 JDK 17 而不是 JDK 18 运行安装程序。在 JDK 17 上安装并运行 NetBeans 后,您可以添加 JDK 18 作为第二个 Java 平台,或编辑netbeans.conf以便 NetBeans 使用 JDK 18 而不是 JDK 17重启后。
  • Don't use the installer at all.根本不要使用安装程序。 Instead, just download the zip of NetBeans named netbeans-13-bin.zip , unzip it, and then edit netbeans.conf so that NetBeans will use JDK 18.相反,只需下载名为netbeans-13-bin.zip的 NetBeans zip ,解压缩,然后编辑netbeans.conf ,以便 NetBeans 使用 JDK 18。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM