Java -version points to wrong directory [duplicate

2019-05-10 02:43发布

问题:

This question already has an answer here:

  • Java path..Error of jvm.cfg 19 answers

I have set my environment variables up. Window 7 - 32 bit

C:\Users\user>java -version
Error: could not open `E:\lib\i386\jvm.cfg'

C:\Users\user>echo %JRE_HOME%
C:\Program Files\Java\jre7\bin

C:\Users\user>echo %PATH%
C:\Program Files\PC Connectivity Solution\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\jdk1.6.0_22/bin;C:\Program Files\Java\jre7\bin/bin;C:\Ruby193\bin;C:\Ruby187\bin

C:\Users\user>java -version
Error: could not open `E:\lib\i386\jvm.cfg'

I checked on E: there is nothing on the location. I have JRE7 and jdk1.6.0_22.

Could you please give me solution for this?

I tried to use this solution, Not able to properly set up the path of java in Windows 7 , 64 bit however, while clicking on JAVA present on control panel it is giving me same error message. [ Error: could not open `E:\lib\i386\jvm.cfg']

回答1:

When you install a JRE, the installer writes a special java.exe in the Windows system directory (ex . C:/winnt/system32/java.exe). This java.exe will look in the registry to get the location of the current JavaHome.

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion]  (64 bits or 32 bits only)
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment\CurrentVersion] (32 bits installed on OS 64 bits)

and then get the path of the JRE for the version marked as current.

For a 32 bits JRE installed on a Windows 64 bits installation :

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment\CurrentVersion] -->  1.8

and then

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment\1.8\JavaHome] --> C:\Program Files (x86)\Java\jre1.8.0_31

So verify the values in the registry and clean up you PATH because you don't need it to launch java.exe from the command prompt by typing only java.exe.

If your setup is correct, you will be able to override the default JRE without modifying your PATH :

> java -version:"1.6" MyClass  (force the jre 1.6 installed to be used)

The JAVA_HOME and JRE_HOME environment variable are not used by the JRE installed in the "Program Files" with the installer, they are used by convention by IDE, tools or application server.



回答2:

why do you have a jdk 1.6 and a Jre 7?and your Java environment variables are set wrong. the jdk and jre paths have a backward slash before the bin. and your jre has \bin\bin

edit I am referring to your path variable here please use either jdk 1.7 or jdk 1.6. that choice depends on development you yoi are doing. and the jdk contains a Jre. so you do not need to download both.

also if you are not confident about manually setting the path, you could always run the installer. the setup does all the required steps for you.



回答3:

When Java is installed on Windows 7 using the installer download, a copy of java.exe is installed by default in C:\Windows\System32 and a link to java.exe is created in C:\ProgramData\Oracle\Java\javapath which is added to your Path environment variable. When you run "java -version" it is useful to ask what java executable does that invoke and where is it located? Your issue may be simplified and possibly solved by renaming or removing conflicting Java executables from the System32 folder and from other locations in your personal Path and the system Path in which they may also be installed.



回答4:

Type

echo %PATH%

and check from which location your java.exe is invoked. Path could be overriden by old java installation.