我应该将JAVA_HOME用于OpenJDK的JDK还是OpenJDK的JRE? [英] Should I use JAVA_HOME for OpenJDK's JDK or OpenJDK's JRE?

查看:131
本文介绍了我应该将JAVA_HOME用于OpenJDK的JDK还是OpenJDK的JRE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近的许多情况下,但是现在我尝试使用安装程序,该安装程序会引发错误,并说"Java未安装",即使JAVA_HOME设置为AdoptOpenJDK安装程序为Windows 10 64x安装的JDK.我找不到修复它的方法,无论如何,今天我尝试安装Netbeans 8.2,它显示了此错误,但是我发现您可以将参数传递给安装程序(--javahome),然后错误消息从"JDK"更改为找不到(在您的计算机中)"到找不到JRE(在给定位置)",这甚至很奇怪.然后我将JRE作为javahome传递了出来,并且它起作用了,这让我感到惊讶,在安装程序中,您可以选择netbeans应该使用的jdk,并且它可以正确显示已安装的jdk.太...为什么会这样?

JAVA_HOME是"C:\ Program Files \ AdoptOpenJDK \ jdk-13.0.2.8-hotspot \"在安装过程中我没有更改它

-javahome参数为"C:\ Program Files \ AdoptOpenJDK \ jdk8u242-b08-jre"我在安装它后意识到它不在路径中

但是我100%确定"C:\ Program Files \ AdoptOpenJDK \ jdk-13.0.2.8-hotspot \"位于Path中,这很奇怪,因为据推测,根据我阅读的AdoptOpenJDK安装程序的说明,里面的JRE?还是至少不应该JDK是JRE的超集?

由于此答案,我将JDK路径保留为JAVA_HOME. JAVA_HOME是否应指向JDK或JRE?

解决方案

您的实际问题尚不清楚,但这看起来像是X-Y问题.真正的问题是您在安装NetBeans 8.2时遇到问题(对吗?),但是您错误地得出结论,认为原因与 JAVA_HOME 的设置有关.不是.

首先,从NetBeans 8.2下载页面 ,注意"要安装和运行Java SE,Java EE和所有NetBeans捆绑包,必须使用JDK 8. Netstrongs 8.2不能在JDK 9或更高版本上运行.您的问题是您尝试将JDK 13与NetBeans 8.2一起使用.那只是行不通的.

第二,您无需设置环境变量 JAVA_HOME 即可使NetBeans 8.2正常工作.我只是故意破坏了 JAVA_HOME 的设置,然后NetBeans 8.2重新启动并可以正常工作.这是一件好事,因为出于某些与NetBeans完全无关的其他原因,您可能合法地希望将 JAVA_HOME 设置为任意JDK,并且如果它依赖于 JAVA_HOME <,则这样做可能会破坏NetBeans 8.2./strong>.

第三,NetBeans也不关心您的 PATH 设置.(顺便说一句,NetBeans忽略 JDK_HOME PATH 意味着您可以安装不同版本的NetBeans,每个版本使用不同的JDK,并安全地同时运行它们.)

要明确指定NetBeans 8.2安装应使用的JDK:

  • 找到文件 netbeans.conf .这是一个文本文件,位于NetBeans 8.2安装目录下的 etc 目录中.
  • 在任何文本编辑器中打开该文件,然后找到包含文本 netbeans_jdkhome 的行.
  • 如果该行以#(表示带注释的行)开头,请删除该行,然后设置 netbeans_jdkhome 以指定JDK 8安装的路径.在我的Windows 10计算机上,该行如下所示: netbeans_jdkhome ="C:\ Java \ jdk1.8.0_221" .
  • 确保只有一行未注释的行将值设置为 netbeans_jdkhome (将其保存到JDK 8安装目录中),然后将所做的更改保存到 netbeans.conf 并(重新)启动NetBeans 8.2.

希望这是解决问题所需要做的一切,但如果不是,请更新您的问题以阐明需要解决的确切问题.

In many recent situations, but right now I tried using a installer, that throws an error and says something along the lines of "Java not installed" even though the JAVA_HOME is set to the JDK installed by AdoptOpenJDK installer for Windows 10 64x. I couldn't find a way to fix it, anyways today I tried to install Netbeans 8.2 and it showed this error, but I found out you could pass an argument to the installer (--javahome ) then the error message changed from "JDK was not found (in your machine)" to "Couldn't find a JRE (in the location given)", which was even weirder. Then I passed the JRE as the javahome and it worked, which surprised me, in the installer you can choose which jdk should netbeans use and it correctly displayed the jdk installed. Sooo... why is this happening?

Edit: JAVA_HOME is "C:\Program Files\AdoptOpenJDK\jdk-13.0.2.8-hotspot\" and I didn't changed it for the duration of the installation

the --javahome argument was "C:\Program Files\AdoptOpenJDK\jdk8u242-b08-jre" and I realized after installing it that it wasn't in Path

But I'm 100% sure that "C:\Program Files\AdoptOpenJDK\jdk-13.0.2.8-hotspot\" was in Path, which is weird because supposedly according to something I read the AdoptOpenJDK installer installs the JDK with the JRE inside? or atleast shouldn't the JDK be a superset of the JRE?

Edit 2: I've left the JDK path as JAVA_HOME because of this answer. Should JAVA_HOME point to JDK or JRE?

解决方案

Your actual question is unclear, but this looks like an X-Y problem. Your real problem is that you had problems installing NetBeans 8.2 (right?), but you are incorrectly jumping to the conclusion that the cause was somehow related to your setting of JAVA_HOME. It isn't.

First, from the NetBeans 8.2 download page, note that "JDK 8 is required for installing and running the Java SE, Java EE and All NetBeans Bundles. NetBeans 8.2 does not run on JDK 9 or later". So at least part of your problem is that you were trying to use JDK 13 with NetBeans 8.2. That just won't work.

Second, you don't need to set the environment variable JAVA_HOME for NetBeans 8.2 to work. I just deliberately sabotaged my setting of JAVA_HOME, and NetBeans 8.2 restarts and works just fine. This is a good thing, because you may legitimately want to set JAVA_HOME to some arbitrary JDK for some other reason completely unrelated to NetBeans, and doing so might break NetBeans 8.2 if it relied on JAVA_HOME.

Third, NetBeans does not care about your PATH setting either. (As an aside, NetBeans ignoring JDK_HOME and PATH means that you can install different versions of NetBeans each of which uses a different JDK, and safely run them concurrently.)

To explicitly specify the JDK that your NetBeans 8.2 installation should use:

  • Locate the file netbeans.conf. It is a text file and resides in the etc directory under your NetBeans 8.2 installation.
  • Open that file in any text editor, and locate the line containing the text netbeans_jdkhome.
  • If the line starts with a # (denoting a commented line) remove that, then set netbeans_jdkhome to specify the path to your JDK 8 installation. On my Windows 10 machine that line looks like this: netbeans_jdkhome="C:\Java\jdk1.8.0_221".
  • Ensure that you have exactly one uncommented line setting a value to netbeans_jdkhome (which will be to your JDK 8 installation directory), then save your changes to netbeans.conf and (re)start NetBeans 8.2.

Hopefully that is all you need to do to resolve your issue, but if not please update your question to clarify the precise problem that needs to be solved.

这篇关于我应该将JAVA_HOME用于OpenJDK的JDK还是OpenJDK的JRE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆