I normally still use Java 7 for all my coding projects (it's a company "politics" issue), but I installed Java 8 for one third-party project I am contributing to. Now, it seems I cannot have Java 8 installed in Windows 7 x64, and still use Java 7 by default:
C:\>"%JAVA_HOME%\bin\java.exe" -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
C:\>java.exe -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
As you can see, JAVA_HOME is completely ignored.
I also have Java in the path, using "%JAVA_HOME%\bin", which resolve correctly to Java 7 when I check the path in a DOS box, but it still makes no difference.
I checked in the "Java Control Panel" (not sure if this affects the default command-line Java version). Under the "Java" tab, the "View..." button, you get to see "registered" Java versions. I can add all the versions under the "User" tab, but under "System" there is only Java 8, and no way to change it.
Am I missing something, or did Oracle just make it impossible to use Java 7, unless I de-install Java 8? I don't want to have to specify the "source" and "target" everywhere, and I don't even know if it is possible for me to specify it everywhere, where Java is used.
EDIT: What I did is I de-installed all Java. Then installed the latest Java7 (both 86 and x64), and then the latest Java8 (both 86 and x64). After I did that, I noticed that the x64 JDK was gone. It seems Java8 killed it. So I re-installed the JDK 7 x64, after the JDK 8 x64. Still, JDK7 x64 did not seem to "replace" the "java.exe" which is copied into the "Windows" directory itself (I assume THAT is the problem).
When you install jdk8 it adds an entry like this
C:\ProgramData\Oracle\Java\javapath
to beginning of your PATH environment variable, removing this entry should resolve your problem.
You can select the JRE version from the command line with the -version: option.
> java -version:"1.7" MyClass
should select the 1.7 JRE if installed properly.
The list of the properly installed JRE is in the registry, see the key :
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment (32bit)
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment (64bit)
You can set the "CurrentVersion" there if you want a different default version than the latest.
See http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html#options
Don't modify your PATH to point to a particuliar JRE, let the special java.exe in Windows/system32 do the job.
Windows and Unix both find programs using their PATH environment variable. You have an java.exe in your Windows\System32 which is appearing before your "preferred" version of Java.
Change the PATH to be the one you need, or specify the full path when you need a different version.
2 Steps
1
Change registry key **HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion** to point to 1.7
2
Copy java.exe,javaw.exe and javaws.exe from your java 1.7 version to Windows\System32 folder
(Since the corresponding files of java 1.8 are already there, you might have to overwrite with admin permissions)
3
(OOps actually not required 3rd step )
Open a new cmd window and check
java -version
Looks like you have to check where in your PATH is located your JAVA_HOME variable, the PATH is evaluated from left to right. A tip for you is to do all your Java system variables configuration at the beginning of your PATH.
PATH = %M2_HOME%\bin;%JAVA_HOME%\bin;C:\ProgramData\Oracle\Java\javapath;...
Probably that's why after doing this:
- java -version
you are getting this:
- java version "1.8.0_05"
because there are other areas in your PATH that are pointing to other java.exe, for example C:\Windows\System32 or C:\ProgramData\Oracle\Java\javapath etc.
I had to make 2 changes for it to work:
Changed the Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion' to 1.7 from 1.8
The Java 8 installation adds a new entry to the PATH environment variable 'C:\ProgramData\Oracle\Java\javapath'. I removed this entry from the PATH.
Related
I am new to Java programming. I have installed Java SE 11 (LTS) (JDK 11.0.8) on my OS. Note that former Java also has jre folder in it. But Java 11 onward there come only JDK folder.
So, I have set JAVA_HOME environment variable as well as, included jdk\bin in path as well.
By checking on cmd java version shows as follow:
C:\Users\user>java -version
java version "11.0.8" 2020-07-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)
Then I installed eclipse 2020 09 version. But by making a simple Hello World project does not work.
And shows this error multiple times.
Description Resource Path Location TypeThe project was not built due to "Failed to init ct.sym for C:\Users\Irfan Umar\AppData\Local\Temp\eoiE758.tmp\plugins\org.eclipse.justj.openjdk.hotspot.jre.minimal.stripped.win32.x86_64_14.0.2.v20200815-0932\jre\lib\jrt-fs.jar". Fix the problem, then try refreshing this project and building it since it may be inconsistent HelloWorld Unknown Java Problem
What is the solution, I believe it is related to JRE not provided in JDK now.
Eclipse uses Java in two ways. It runs Eclipse with Java, and it allows specifying Java Runtime Environments in Preferences. I rarely see any reason to set JAVA_HOME anymore, because I specify the paths to the JDKs I want to use. I always have multiple JDKs installed.
I specify which JDK to use to run Java by setting the "-vm" path in the "eclipse.ini" file (which points to the "bin" directory).
I specify which JDK to use to compile code by adding JREs in preferences, and sometimes editing the "Execution Environments" (subsection of "Java Runtime Environments") to point to specific JREs.
I have recently uninstalled JDK 11 and installed JDK 8. For confirmation, I want to check which JDK is installed on my Windows 10 machine. I typed java -version on cmd then get the error message
java is not recognized as an internal or external command
How to know which JDK version installed on my PC?
you might need to add path in environment variables which you can find in Control Panel
open the Jdk where you installed and add until /bin in the path in environment variables.
Add until /bin in path variable in System Variables which is residing in Environment Variables.
Then do
java -version
which might show up.
If still problem persists, try restarting your pc and see.
You need to update your Windows path to include your %JAVA_HOME%\bin directory. %JAVA_HOME% is the directory that you installed Java into and is also an environment variable that you need to configure for command line execution of your applications. You can edit both of these in the Windows control panel and you should restart.
When you run java -version you will see the internal version number. This is explained here: https://en.wikipedia.org/wiki/Java_version_history.
Basically, you can ignore the 1. when reading version number. The _xxx is a reference to the most recent patch or build release.
On Windows 10, this required mapping the environment variable for JAVA_HOME to the JDK installation directory. Use these steps:
Run the installer for the JDK. (available for windows here: https://www.oracle.com/java/technologies/downloads/#jdk17-windows)
windows key -> Environment Variables, select the only result
In the System Properties window that opened, select Environment Variables
Select new button under the User variables section
Variable name: JAVA_HOME, Variable Value: <The JDK filepath from step 0>
ok all open menus
Close any open cmd prompt windows
open a new cmd window and type echo %JAVA_HOME% It should print the installation path for the JDK.
To get your jdk location in Windows, run this at a command prompt:
where java
This lists any and all locations of java.exe, including from your JAVA_HOME. For example, the 3rd line here reflects my JAVA_HOME location, where I'm pointing to JDK 8:
C:\Users\me> where java
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk1.8.0_202\bin\java.exe
Note for comparison that java -version does not reflect my JAVA_HOME location and in fact shows java version 11 instead of 8:
C:\Users\me> java -version
java version "11.0.15" 2022-04-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.15+8-LTS-149)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.15+8-LTS-149, mixed mode)
This is confusing because my Java compiles (e.g., via mvn) use JDK 8 since that's what my JAVA_HOME is pointing to. (I'm not even sure where the version 11 it found came from; possibly from when I installed maven.)
Determining the difference between the JRE and JDK you're running has never been straightforward. Seems like java -version used to be a way to do this, but no longer.
Adding to the complexity, you can also supposedly get your Java version info from Control Panel > Programs > Java > About. For me, that shows Version 8. That's despite java -version showing version 11.0.15. And it doesn't change even if I point my JAVA_HOME to JDK 11.
Note that this answer is also helpful. In my case, that helped me determine that I have java.exe and javac.exe at C:\Program Files (x86)\Common Files\Oracle\Java\javapath and C:\Program Files\Common Files\Oracle\Java\javapath. Depending on which one I have listed first in my Path variable, I get different results when i run java -version or java --version. The former seems to work when Java 8 is listed first; the latter when Java 11 is first.
There is something going wrong with my java configuration and it is really bugging me. I am using IntelliJ IDEA and after downloading and installing java 8 I tried to configure my project to use that SDK but I could only locate version 1.6 under /Library/Java/JavaVirtualMachines/. I am new to OS X and I am really confused with the paths.
Looking on my Java control panel I can see I got installed Java 8 but after running java -version on the terminal I get 1.6.0_65.
And the which java gives back /usr/bin/java.
Please help I am completely lost
Here is an example with several Java versions installed side-by-side ...
ls /Library/Java/JavaVirtualMachines/
jdk1.7.0_25.jdk jdk1.7.0_72.jdk jdk1.8.0_05.jdk jdk1.8.0_25.jdk
User can edit ~/.profile to point explicitly at one
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_72.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
And here is result ...
java -version
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
Well something was wrong with the installation. I completely removed the other versions (not 1.6) and reinstalled 1.8 using the default path (as there is no option to change it during installation. Now IntelliJ can see JDK 1.8
Thanks for the help anyway
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'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 :( )