I have a POS that has to be run on java7 and I checked the current version by typing java -version on the command prompt and got the following output:
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
Since I want java7, I thought of editing the environment variables to point to jdk1.7 and when I checked the variables, it was as follows:
I see that it is already pointing to java7 jdk. How is this possible and how to run java7?
UPDATE:
The system variables PATH
I think I figured out the problem but not the solution. The first system variable - C:\ProgramData\Oracle\Java\javapath is causing the trouble here, which has a java.exe in the given path. It might be a product of me directly upgrading java from java7 to java8. But if I remove it, it causes an error in cmd. What could be done?
First thing is, We are not able to see full value of "PATH" variable under user variables section.
I see that it is already pinting to java7 jdk. How is this possible
Usually "JAVA_HOME" is set by apache tomcat service installer since tomcat can only find Java through "JAVA_HOME" variable.
and how to run java7?
In the PATH variable after ruby and python find whether there is jdk 1.8 mentioned anywhere. And replace that with the jdk 1.7 path or you can refer JAVA_HOME in PATH as %JAVA_HOME%
eg: PATH = C:\Ruby....;%JAVA_HOME%\bin;
You are mixing two things.
1. Java home : if you try to echo JAVA_HOME it will point to jdk1.7 ... as you are mentioning. Many of the programs/applications use this env variable to locate java.
2. Path variable : This is where the executables are located. So if you try to run some program/executable, system will try to locate the executable using list of path items. So this should point to jdk 7 if you want to use java directly.
After hours of research I found the problem and the solution, which was quite simple.
Since I used the java notification to upgrade to java8, that had entered the C:\ProgramData\Oracle\Java\javapath to the system variables which had been sort of a pointer to the new jdk.
In order to use java7, I simply needed to bring the jdk1.7 pointer to the top.
Related
Problem:
After installing Java SE version 14.0.1 I tried to run the command java in CMD because I wanted to check if everything works as it should, but an error occurred because CMD could not find what I wanted.
I checked the system environment variable to see if the path for the Java JDK was set, but no, it was not set.
Question:
Why was the path not set by the Java JDK after installing Java SE 14.0.1?
It depens on the installator provider by the combianation of vendor and version. As far as I know the AdoptOpenJDK add the PATH variable
So I'm trying to get the latest version of Java. When I run:
java -version
I get:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
When I run:
javac -version
I get:
javac 1.6.0_65
Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see:
Your system has the recommended vesion of Java.
Java 8 Update 05.
I guess I have a few questions:
1) Don't I want the JDK and my version of Java to match up?
2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise?
Thanks for the help,
Mariogs
The probably "simple" answer is you have two versions of java installed. On the command line you currently use 1.6. Thus the old one is active. In system preferences you see the version of java 8.
Windows:
You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. I recommend the first one.
Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac. IMHO this answer is a good solution.
The Java Platform offers both the JRE and the JDK in order for users to run Java programs. The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit.
The JDK is meant for Java developers - that is, those who build applications/write programs in Java. It contains tools that are needed for Java coding, including -javac to compile programs.
The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development.
The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. The current JDK that you have is Java 8, whereas the current JRE that you have is 1.6.0_65. It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation.
1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE).
2) Likely your path variable is set so that you invoke Java from your Java 6 installation; you need to find the equivalent for your Java 8 installation and set the path for that. Without information about your operating system, we can't help you do that.
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
Let me see if I can clear it up for you.
1)Yes, arguably you nearly want this to be true.
2)It could be few things, but most likely that a previous instillation was not properly removed. So one gets called instead of the other.
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.
I've installed jdk 7 and set up the "JAVA_HOME" to this version. Then, I've installed jdk 6 and I've updated the "JAVA_HOME" to point to jdk 6. After closing and reopening the system, when typing "java -version", I got always :
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) Client VM (build 24.0-b56, mixed mode, sharing)
However, when typing
echo %JAVA_HOME%
I got :
C:\Program Files\Java\jdk1.6.0_45
I didn't understand why java -version don't display the value of "JAVA_HOME"
Java 7 puts a java.exe in c:\windows\system32. You could try to delete these exe's, but I'm not sure Windows will allow it, or restore it after a reboot.
If you want to override it, you must put %JAVA_HOME%\bin as first entry in your PATH, before c:\windows\system32.
Which java starts when you run java -version depends on the PATH env variable, not JAVA_HOME. OS will be looking for java.exe (Windows) like for any other program
if you run java on your command window, it takes java from the PATH variable. JAVA_HOME is used my maven etc...
I believe your PATH variable is pointing to JAVA version 1.7.0_40/bin directory.
According to my understanding, this is nothing to do with your JAVA_HOME environment variable. You are getting java version from C:\windows\system32\java.exe.
If you don’t want that behaviour then in system variables section put %JAVA_HOME%\bin as starting element (Of course you should have JAVA_HOME). (I thought of adding image but I dont have enough reputation to do so :( )
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