Weird issue with environment variables - java

I have this strange Issue with environment variables on my windows 7 system. Its been there for an year and I have had a work around but I need to solve it now:
I have an environment variable JAVA_HOME set as C:\Program Files\Java\jdk1.6.0_39\. And in my PATH I have added %JAVA_HOME%\bin;.
But when I do java -version it prints "1.7.0_11" and when I do javac -version it prints as expected 1.6.0_39
I do not know why 1.7.0_11 is printed for java -version. I have checked my PATH and have added JAVA_HOME only once. How can I know which env variable is responsible for using my java.exe? How do I avoid it?

It's almost certainly a version of java.exe in c:\Windows\System32, which is likely to come earlier in your path than the part which refers to JAVA_HOME.

Ok, hopefully %JAVA_HOME\bin%; is a typo, but if not, it should be %JAVA_HOME%\bin.
For the rest - java -version is looking for your JRE, not your JDK. javac is looking for the JDK.
Check to see if you have a JRE-related environment variable. As well, check your path for any hard references to the Java 7 JRE. Finally, look in C:\Windows\System32 and see if there is a java.exe there.

Java.exe is installed on windows twice. The first location is where you expect it: under your JAVA_HOME. The second one is under c:/windows. Since this path always wins any other user defined path you are running java from here. If you want to hold several java environments and switch between them by changing your JAVA_HOME just remove java.exe from c:/windows.

Related

Set Environment variables to Java 11 directory, but CLI -> Java -version is still 1.8?

I have restarted my cmd line after setting the environment variables. Javac is set to version 11, but java is still set to 8?
I have set my path variables like this:
There are no entries from other java versions in my Path variables like in this question:
Installed Java 14 but Java -version still showing old Java
I have double checked that java.exe and javac.exe are in fact at location C:\Program Files\Java\jdk-11.0.7\bin:
I have read the other questions to this problem on Stackoverflow, but it was always that they set a wrong path, forgot to append /bin or had old paths to other java versions in their environment variables. I also tried reinstalling Java 11 and restarting the computer (as last idea). What else could I try?
This can be caused by multiple different reasons.
Try 'where java' and 'where javac' to see where they point to. You should thenbe able to find the exact path from where java and javac are being called in your environment.
Also ensure that you only have one jdk/jre in your Path. You can try to move %JAVA_HOME% to be the first element in the Path list.
Move %JAVA_HOME%\bin to the top and then check java -version in a new cmd window. Make sure you do it in both, User variables as well System variables. Check this to learn more about a similar problem and its solution.
You can also put in your system variables:
Click on Path
Edit
Click on New
Add the whole path something like: C:\Program Files\Java\jdk11.0_172\bin (this should be your path where the jdk is installed).
This will work and you will have java 11.
I made 2 changes in order to reflect java -version as Java11
Control Panel --> Edit environment variables for ur account
-->System Variables --> Path
Make sure %JAVAHOME%\bin should be on 1st place
Make sure C:\Program Files\Common Files\Oracle\Java\javapath should be on 2nd place.

Java 9: java.dll not found [duplicate]

why do I get this? How can I fix it?
C:\Users\ash>java version
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.7.0_01', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
The accepted solution for Reinstalling ALL JDKs was a bit harsh.
I too experienced this problem and here is my 2 cents:
This problem started happening since I installed JDK 8 and still had JDK 6 installed. I need for different projects I'm working on.
I noticed I had both a User and a System %JAVA_HOME%, so I removed my User %JAVA_HOME% variable and left only the system one.
I also noticed that in my Oracle installation there was some Java executables and I believe those where the ones conflicting since both my Oracle and Java installations were in my %PATH% variable.
I removed all Java paths from my %PATH% Variable and only left the %JAVA_HOME%\bin at the start of the variable for avoiding any conflicts with the Oracle installation.
I had a similar issue after installing the java 1.8.
To fix this go to Advance System setting --> path and remove
C:\ProgramData\Oracle\Java\javapath;
Removing
C:\ProgramData\Oracle\Java\javapath;
work like charm
Reinstall JDK and set system variable JAVA_HOME on your JDK. (e.g. C:\tools\jdk7)
And add JAVA_HOME variable to your PATH system variable
Type in command line
echo %JAVA_HOME%
and
java -version
To verify whether your installation was done successfully.
I had a similar issue after installing the java 10.0
To fix this go to Advance System setting --> path and remove
C:\ProgramData\Oracle\Java\javapath;
I had to remove the Common Files javapath from the 'Path' that was conflicting, in order to make it work. Now thankfully the java -version works just fine.
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
Make sure your JDK Path variable is directing to the \bin folder and is at the top of the list, because it always uses the first match. By moving it to the top you can make sure that no other path is matched first.
If there's any other entry that has a file called java (such as C:\ProgramData\Oracle\Java\javapath) it will run the command against that file instead of the java file in your JDK. There's no need to reinstall the entire JDK unless your files are corrupt or damaged for some reason.
This problem generally occurs in Windows when your "Java Runtime Environment" registry entry is missing or mismatched with the installed JDK. The mismatch can be due to multiple JDKs.
Steps to resolve:
Open the Run window:
Press windows+R
Open registry window:
Type regedit and enter.
Go to: \HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\
If Java Runtime Environment is not present inside JavaSoft, then create a new Key and give the name Java Runtime Environment.
For Java Runtime Environment create "CurrentVersion" String Key and give appropriate version as value:
Create a new subkey of 1.8.
For 1.8 create a String Key with name JavaHome with the value of JRE home:
Ref: https://mybindirectory.blogspot.com/2019/05/error-could-not-find-javadll.html
I edited my path to put the Oracle JDK at the start of the path and that fixed it.
Problem:
We had the same problem in our Windows 2012 server. We used JAVA_HOME environmental system variable, an we used in the PATH this kind of settings: ...%JAVA_HOME%/bin;...
and no other java related settings was in the PATH.
The problem was we had a space at the end of the value of the JAVA_HOME variable. Like 'C:\Program Files\Java\Jdk 1.8.0_172 ' so the %JAVA_HOME%/bin meant 'C:\Program Files\Java\Jdk 1.8.0_172 \bin'. So because the value was split by space and the system tried to find java.exe at 'C:\Program Files\Java\Jdk 1.8.0_172' where it is obviously not.
Solution was: Delete the space from the end of value of the JAVA_HOME !
Uninstall Java from machine
Check Java folder is deleted from Program Files
Check Registry does not have any instance of Java
Open system Variables and delete the ONLY java path from PATH
Now install the new version again.
Set the Path in System Variables.
This process cleans up all the traces of java and then install fresh java.
Note: This issues occurs when there is multiple installation and uninstall done.
You could be using a 32 bit version of java on a 64 bit environment.
Export the registry hive form HKLM\Software\JavaSoft and import into HKLM\Software\Wow6432Node\JavaSoft. For 1.6 I only needed JavaHome and RuntimeLib values.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Javasoft]
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Javasoft\Java Runtime Environment]
"CurrentVersion"="1.6"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Javasoft\Java Runtime Environment\1.6]
"JavaHome"="C:\\Java\\jre"
"RuntimeLib"="C:\\Java\\jre\\bin\\client\\jvm.dll"
None of the above worked for me, unfortunately.
The error solved when I uninstalled the old JDK versions that were installed on my computer. I did it simply with the "Uninstall or change a program" tool (under the Control Panel).
I removed the "C:\Program Files (x86)\Heroku\bin" from PATH variable and the problem has gone. I think it is probably the Heroku require different version of Java. So check all directories in your PATH variable, remove the possible ones may have confliction.
If you face this error in cmd with another error as "could not find runtime environment" after you have done all settings in Environment Variable. Then you just need to run jre.exe in your jdk folder and reinstall it and then recheck it by java -version command. Hope it will help you.
rename file "C:\Windows\System32\java.exe" to "C:\Windows\System32\java_old.exe"
CMD --> java -version
done.
In my case the regedit information was correct and the problem was solved by doing the below:
1) setting JAVA_HOME to jdk - set JAVA_HOME=C:\Program Files\Java\\bin
2) setting PATH to jre - set PATH="C:\Program Files\Java\\bin"
after adding the requirements path as illustrated up and deleting C:\ProgramData\Oracle\Java\javapath;. don't forget to reopen your editor.
Go to CMD and type the following:
SET PATH=C:\Program Files\Java\jdk1.8.0_291\bin
(here jdk1.8.0_291 represents your java version, it may differ for you)

javac not found after set environment variable

I am running on a Windows 7 machine.
I installed Java jdk 1.7.
I have set the Path and PATH environment variable to point to the Java jdk 1.7/bin directory.
Executing java -version in the command prompt yields Java version 1.7.0_45.
However when I execute javac it says that:
javac is not recognized as an internal or external command
I am really stumped on this problem. All other threads seem to get similar issues resolved via changing the environment variable but this is not solving my problem in this situation.
Edit
When I run java -version in Console2 it says that the currently used version of Java is 1.6 and I am not sure why this is the case.
Not sure if this is the cause, but in the path you posted
C:\Program Files\Java\jdk1.7.0_45 \bin
Looks like an extra space in between of "jdk1.7.0_45" and "\bin"
Also it's always good to append ";" at the end.
PATH = C:\Program Files\Java\jdk1.7.0_45\bin;
Chnage it to C:\Progra~1\Java\jdk1.7.0_45\bin and it shall work like magic :)

How to set path for Jre 6 when jre 7 installed?

I am programming through java 1.6 u_17, but i have JRE version 6 and JRE version 7 installed, so how to run my compiled program from JDK 1.6 to run through the JRE 6 only?
By Default, it runs my class files through JRE 7, how to change this behavior? Any idea of setting Class path in windows 7, as we does it for JDK.
The following is shown in my command prompt
E:\JAVA>javac -version
javac 1.6.0_17
E:\JAVA>java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)
This is for my SET command showing the Windows 7 environment paths
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Administrator\AppData\Roaming
ClassPath=C:\Program Files\Java\jdk1.6.0_17\bin\mysql-connector-java-5.1.5-bin.jar;
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=RANDMATE-PC
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Administrator
JAVA_HOME=C:\Program Files\Java\jre6\bin;
LOCALAPPDATA=C:\Users\Administrator\AppData\Local
LOGONSERVER=\\RANDMATE-PC
NUMBER_OF_PROCESSORS=2
OS=Windows_NT Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_17\bin;C:\Program Files\Java\jre6\bin;C:\Program Files\MyS
QL\MySQL Server 5.1\bin;C:\Program Files\UltraEdit\;C:\Program Files\Jar2Exe Wizard\;C:\Program Files\Java\jre6\bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 6 Stepping 5, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0605
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\ADMINI~1\AppData\Local\Temp
TMP=C:\Users\ADMINI~1\AppData\Local\Temp
USERDOMAIN=RANDMATE-PC
USERNAME=Administrator
USERPROFILE=C:\Users\Administrator
windir=C:\Windows
Looks like you are using Windows. Please go the Environment Variables and define a user variable as:
Right Click(My Computers) -> Advanced -> Environment Variables -> Add
Variable Name = JAVA_HOME
Variable Value = Root Folder of Java 1.6.0_17 installation
Also in the same screen, please check the PATH variable and make sure **bin** Folder of Java 1.6.0_17 installation is added in the path preferably in the beginning and remove the Java 7 from the path, if it is there.
I fix this problem by removing the java.exe in system32 folder. And then in the cmd the java command refer to the jdk set in the path enviroment variable.
java.exe is also available in C:\windows\system32 and in your case its version might be 1.7..
Since your path has C:\windows\system32 first. no matter how to set rest of the path, sonar always will load jre7. (refer to conf\wrapper.conf in Sonar directory, by default it has wrapper.java.command=java)
To fix this, change following property of the "wrapper.conf" file
wrapper.java.command=C:\Program Files\Java\jdk1.6.0_XX\bin\java
this will fix the issue irrespective of the path variables.
For those who had the same problem I suggest reading this thread:
https://superuser.com/questions/479889/wrong-java-version-being-reported
Quote of wmz: "To check what actually executes when you run 'java -version' run from command line:
for %I in (java.exe) do #echo %~$PATH:I"
Windows is checking the PATH variable to find an executable named java and using that to launch your application. It is quite normal in a development environment to have many installations (as you do). However this calls on you to manage your environment.
There are two ways for you to set environment variables in Windows. By going to My Computer > Advanced Settings > Environment Variables as described above, you can set a variabler to your JDK installation and then update the Path to find the bin directory in that installation. Youy have the choice of updating System variables (all users) or user variables (your account only).
Personally, I prefer not to use the system/user environment variables as this provides less flexibility. You can use bat files to explicitly set the Path for a specific moment in time, or indeed to override the JAVA_HOME to point to a different installation.
If you are using an IDE you can usually specify the target runtime on a per project basis. Alternatively, when running the program, provide the fully qualified path to the version of the java executable you wish to use.
I had same problem. Issue is that Java installation will copy a java.exe, javaw.exe and javaws.exe to windows/system32 directory. You must have installed JDK7 recently.
I just removed those files from Windows/System32 directory, however, kept older version in path. This solved the issue.
Try it out.
I was facing the similar problem. I am using Java 7 and Java 8 together. The Java 8 was installed in the machine but the 7 set-up I copied from another system. I have already set the JAVA_HOME & path pointing to 7. But when I try to echo %path%, it shows the Jdk 8 in the class path. after lots of google, I have found "C:\ProgramData\Oracle\Java\javapath" in the path. Removing the line from the path solved the problem.
Background
I'm using Windows 8.1 and I have both JDK6 and JDK8 installed. For development purpose, I needed to get java version "1.6.0_45" over the command java -version and javac 1.6.0_45 over javac -version. The second command was working as expected after setting JAVA_HOME as Home folder of JDK6 and adding %JAVA_HOME/bin% in Path. However the first command was still returning java version "1.8.0_71"
Troubleshooting
I could find the an entry in the Path environment variable which points to C:\ProgramData\Oracle\Java. This folder actually contains short cut to java.exe of JDK8.
Proper solution: Uninstall JDK 8
Workaround:Edit the short cut file so that it points towards java.exe inside %JAVA_HOME%\bin (Please replace the variable with actual folder)
set the PATH variable to your jdk6\bin directory. so that it will pick the javac and java from jdk6.
for setting the path variable go to Environment Variables.
After setting the path variables you need to restart your command prompt. (NOT the computer).
Just right click on MyComputer, then Advanced System Settings-->Environment Variables-->New
Then in the "variable Name" text field add the string "PATH" or if it already exists select PATH from the list and click edit then append the path for "bin" folder in java in program files to the Variable value text field followed by a semicolon (;), if not exits add the path of bin directory of your java folder in "Variable Value" field and click "OK".
If you want to check the result, open up a command prompt and type "java" then hit enter.
For windows 7(X86) path setting:
first step:
Mycomputer(Right click)-->properties-->advanced settings-->environment variales-->new
(user variable)
on this first varible name: "" JAVA_HOME "" value: "" C:\Program Files\Java\jdk1.7.0_45 ""
second variable name: "" PATH "" value: "" C:\Program Files\Java\jdk1.7.0_45\bin;.; ""
There are two types of path for java : Permanent & Temporary.
Here is the video tutorial describing how to set path for Java?
How to Set path for Java : https://www.youtube.com/watch?v=rM4Qq3Ua7Sk
This video tutorial will guide you in setting permanent and temporary path for Java. Simply follow the steps. This will work with any version of Java, JDK or JRE. In video I have used path of JDK, Simply copy path of JRE instead of JDK and rest is same.
OR read the tutorial here : How to Set path for Java : http://aatul.me/2011/08/24/how-to-set-path-for-java/
Hope this solutions will help you.

JAVA_HOME environment variable and Java JDK fun

I wanted to get Java running at 1.6xxx - I changed the JAVA_HOME variable and pointed it to the directory C:\Program Files\Java\jdk1.6.0._16.
I restart the PC - and I think I can check which version of Java my machine is pointing at - but it still points to the older version of Java e.g v1.5.0_16
Can you help me rejog my memory on correct setup for Java JDK?
You need to reset your path variable to point to 1.6
something like
Additionally, make sure the variable JAVA_HOME is also set with the above location.
JAVA_HOME is used by other applications, such as Tomcat. Windows just checks the PATH environment variable for locations where it can find the java executable.
Try this on the cmd shell:
> java -version
java version "1.5.0_16"
> set PATH=%JAVA_HOME%\bin;%PATH%
> java -version
This Image will explain all steps.
For More Explanation

Categories