问题
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?
回答1:
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 setnetbeans_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.
来源:https://stackoverflow.com/questions/60424617/should-i-use-java-home-for-openjdks-jdk-or-openjdks-jre