I have java 7 and java 8 both installed on my windows system under C:\Program Files\Java
In the environment's path I specified the path of java 7 like this.
%JAVA_HOME%/bin where JAVA_HOME = C:\Program Files\Java\jdk1.7.0_17
But when I type javac -version it shows javac 1.7.0_17 which makes sense
but when I do java -version it shows
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
Any idea what may be the problem here?
Edit The installed folder :
And one more thing echo %PATH% has only one occurence of JDK that is for java 7 and no occurence for JRE found in it.
The issue is occuring most probably because you have a JRE in your PATH, before your JDK. This usually happens when we add JDK in the PATH and do not remove previously added JREs. Thus when you do java it points to the JRE and when you do javac it points to the other version/JDK (since the JRE does not have a javac in it)
If you don't have any JREs in your path, then you can copy your %JAVA_HOME% and paste it first in your path variable (make sure its before the system32 path).
A possible reason for why this works is explained in this answer:
JRE also puts a java.exe to c:\Windows\System32, that's how first command is resolved. Second command is resolved by the C:\Program Files\Java\jdk1.7.0_02\bin entry in your PATH variable.
If (and when) you are developing from the command prompt, you have to adjust the PATH variable so that C:\Program Files\Java\jdk1.7.0_02\bin is before c:\Windows\System32.
Go to Environment Variables in your windows machine.
In User Variables : Make sure to set
- Your user variable "JAVA_HOME" value to "C:\Program Files\Java\jdk-xxxx\bin"
where "jdk-xxx" is the version of your jdk.
In System Variable :
- Add same "C:\Program Files\Java\jdk-xxxx\bin" value to "Path" variable.
make sure to move the added value on top of all values.
Now try running java -version and javac -version.
worked for me. :) Here i've linked my screenshot
Ok, as you said that you have no JRE on your path, I assume that where java (if you have Windows 7) will give you C:\Windows\System32\java.exe.
Changing the java running
Try using the Java-Settings Dialog from the control panel to change the Java System Version, which is currently active. This should change the version java -version is returning. If this does not work, you will probably need to reinstall the Java version of which you want to run the java command, specify the path explicitly, write you own wrapper (which works if you are in the same directory as the wrapper) or place the JRE path before C:\Windows\System32\ onto your path (don't know if last option really is a good one).
A wrapper could look just like this:
#"C:\Program Files\Java\jre7\bin\java.exe" %*
and you can either name it java.bat (where it will work if you are in the same directory or put it in PATH before C:\Windows\System32\java.exe or you could name it java7.bat and put it anywhere on you path to be able to run the Java 7 JRE if you desire to do so.
A wrapper is also a good option if you want to change the JAVA_HOME when running.
Changing the javac running
If you want to run a different javac hit Windows + Pause and open the system dialog to change the PATH so it contains the path to your JDK 8 instead of your JDK 7. You will need to restart your command line for changes to show.
It's all about $JAVA_HOME system variable
In my case
for Windows
(moving jdk8 -> jdk9 -> jdk11) I had a garbage
left by jdk8 in PATH (before JAVA_HOME:"C:\path\java11")
so I just remove C:\ProgramData\Oracle\Java\javapath_jdk8 from system variables
// or place it below javapath_jdk11
for MAC edit .zshrc to have
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-???.jdk/Contents/Home"
To resolve such kind of environment issue I always believe on command whereis,
To do the same in windows download whereis.exe then set in path and execute the command
whereis java.exe
whereis javac.exe
You will easily find the exact path from which location java is being called in environment as well about javac.
Please check that you have replaced "C:\ProgramData\Oracle\Java\javapath;" with %JAVA_HOME%/bin in the PATH variable. This did the trick for me.
FOR LINUX USERS
if java and javac are showing different versions, then you can easily set them to the correct or same versions
step 1
sudo update-alternatives --config java
output :
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode
* 2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
this will show the following results, start(*) indicates the javac version that your system is using. You can change it by selecting your required version.
step 2
sudo update-alternatives --config java
output :
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
* 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Now again you can select the version you want to run for java.
This way you can ensure that java and javac are having the same versions.
A side note with the accepted answer. I couldn't leave the trail of java-1.8.0, but I have installed java 17 and want java "17", so, I placed java 17 bin path in the first place (top most ) of path variables, Home variable and user variable, after that when I type in cmd : java -version, it also show java-1.8.0, then I restart cmd, restart Intellij ide, then I type java -version, then it shows :
java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)
and when I type :
C:\Users\dell>javac -version
It shows :
javac 17
Here is My path variables ScreenShots and command window :
Yes, it is true that in order to deal with mismatching versions we need to modify the PATH variable, and the where command (at least, in Windows) is very handy in finding out which program gets picked first.
There's, however, a twist:
when you look at the contents of yout PATH var after running, for example,
echo %path% > path.txt
you should be aware of the fact that PATH is actually composed of TWO sections: one is System PATH and the other is Current User PATH, and it is System Path that gets evaluated first but printed last.
So simply placing a path to your, say, brand-new JDK in front of everything will be useless as long as there's another place with older version somewhere in the System PATH.
This particular problem is especially common when you have entries such as
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath
in your System PATH. Simply move them to the tail of your Current User PATH section to make these entries the last ones within the search queue.
Check your JAVA_HOME variable under environment variables in Windows machine. Make sure It is pointing to the version that you want.
Next check java jdk path added into your "path" environment variable. Make sure It is the version that you want, Otherwise change this to your JDK version path and then move this to the top of the list of values in path variable. This should mark your desired version as the first choice and all issues will be resolved. I did so, and everything is good.
I have a similar case but both command javac --version show the old version of sdk. It shows "javac 11.0.8" even it should be "javac 19" which is the new version just be installed.
Go to search bar > type > env
click menu "Edit the system environment variables"
Advanced tab > click on button "Environment Variables..."
Under "System Variable" > select "Path" > click "Edit"
Looking for Java path such as "C:\Program Files\Java\jdk-19\bin"
Move the path using "Move Up" or "Move Down" button to the position before "%SystemRoot%\system32" Path
OK > OK
Try the command agian.
Hope this may help you guys.
I guess when you are writing javac, it is getting the value from jre7 which is currently being used by you for development purposes and when you write java version, it is getting the value of the version from the jre8 which is currently being used by the installed applications on your system because your JRE of the system is mentioned before the jre7 which you are using for development
Related
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.
After installing java 11 on my system, runtime continues to be 1.8
Versions of java installed:
C:\Program Files\Java\jre1.8.0_201
C:\Program Files\Java\jdk-11.0.3
JAVA_HOME env variable value: C:\Program Files\Java\jdk-11.0.3
From command prompt running java -version command, expecting to see java 11 info but instead I see java 8.
Changing environment variable value does not change the results, rebooting doesn't seem to be doing anything.
C:\Users\user>java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) Client VM (build 25.211-b12, mixed mode)
expected is that java 11 runtime info is displayed
This just happened to me yesterday. Followed instructions to the letter, and still resulted in a different Java version (1.8.0) instead of the expected (11.0.5) for my downloaded version of JDK11. Funny enough, CMD prompt returned the correct Java version (11.0.5) for the 'javac -version' command, but not for the regular 'java -version' command. I was even told to try uninstalling the existing Java load by my IT expert, as he couldn't think of anything else to try... (I did not end up removing Java)
Turns out he did help me though, perhaps accidentally, but only realized this in hindsight. He told me to try moving the path variable
%JAVA_HOME%\bin
up to the very top of the displayed list of path variables found within the [Edit environment variable] window, for the PATH System Variable option. This did not work immediately, so we figured it had no effect. But I believe this failed because it turns out I had made an oversight when typing the variable in the first place. I had written the word "home" using small caps, instead of large caps. Once I realized my mistake and fixed it to show "HOME" in large caps, my CMD prompt returned the correct java -version of (11.0.5), which matched the javac -version command result.
Please note:
I then tried moving the %JAVA_HOME%\bin variable back to the bottom of the list, where it was originally created, and the java -version command no longer displayed v.11.0.5, but returned the original answer of v.1.8.0. So, I played around a bit and found that this variable needs to be ABOVE the following variable within the existing PATH window:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
Hope this helps others as it helped me!
In the Environment Variables move the JAVA_HOME above like the picture under:
And for Java 8 you can create JAVA8_HOME as in the picture
In system environment variables, append PATH to point to new JDK's bin folder, and remove the old entry
%JAVA_HOME%\bin
I solved this by updating the path in user variables instead of updating in system variables.
Currently I have:
JAVA_HOME = C:\Program Files\Java\jdk-11.0.6
and
path containing %JAVA_HOME%\bin
(in User variable)
I happened to encounter the same issue and this is how I had resolved it.
In cmd/terminal - type where java, this will return all installed versions of java in the system.
In my case, I had installed java 11 somehow some time ago (which I don't remember when). I then deleted the 2 directories of java 11 and Oracle java in the above list carefully. Then Added the JAVA_HOME
and PATH - %JAVA_HOME%\bin accordingly, then it worked.
1: Click on Start (Windows) button.
2: Write Environmental variables.
3: Select the item.
4: Go to Advanced tab.
5: Click Environmental Variables.
6: Look for the one called "path".
7: Check for the java 7 instalation and change it to the path of your Java 11 instalation (C:\Program Files\Java\jdk-11.0.3).
Just make sure that you have added the following path in both user variables and system variable .
C:\Program Files\Java\jdk-11.0.3
it will definitely work , if not try placing them at the top.
On Windows 10
Download JDK 11, run the .exe .
Follow the steps and the problem will be solved!
Copied the link where the jdk is stored.
e.g. :C:\Program Files (x86)\Java\jdk-11.0.12\ bin
System Properties -> Environment Variables -> (in System variables section) -> click the Path -> Edit -> in the path list (C:\Program Files (x86)\Common
Files\Oracle\Java\javapath), click next to it, the Edit text(click ok), now copy the path where the jdk is stored at the end of the path list .
On the same section(in System variables section) -> click New -> variable name : JAVA_HOME and Variable Value : C:\Program Files (x86)\Java\ jdk-11.0.12 (without file bin!!) -> click ok and close the windows.
Open CMD and run -> java - version and next javac -version.
I hope you found it useful.
What is the JAVA_HOME environment variable actually? I'm in doubt. What is done by setting it ? And I have also another question that if we have two or more JDK s in the OS, we can set one version's path to set the $JAVA_HOME variable and another version as the running java in the machine which is shown by "java -version" command.As I think in ubuntu, java --version command gives the JRE configured (running java) version of java and JAVA_HOME variable defines which version to use for compiling java programs. Am I correct? What is actually the difference between the jdks referred by these two outputs-
1. echo $JAVA_HOME
2. java -version
Lets start with what the two commands do.
echo $JAVA_HOME
This outputs the value of the JAVA_HOME environment variable. By convention, this environment variable is set (typically in a shell "rc" file) to the base directory of a JRE or JDK installation. However, none of the Oracle or OpenJDK core java tools depend on this. You set JAVA_HOME for the benefit of 3rd-party tools, to tell them which of possibly many JRE or JDK installations on the system to use.
So running echo $JAVA_HOME will typically give the directory for a JRE or JDK. But it might be unset ... or point to missing directory.
java -version
This runs the java command and tells it to output its own version information. Unlike the previous, if your shell can find a (real) java command, the information it outputs is definitive.
But which JRE / JDK does will the java command come from?
Well that is determined by the shell, and how it (in general) finds commands. For all mainstream Unix / Linux / BSD shells, this is controlled by the PATH environment variable. The PATH variable defines a command search path; i.e. a list of directories where the shell looks for commands.
So if PATH is /usr/bin:/bin:/usr/local/bin:/home/joeuser/bin:/usr/java/jre-x.y.z/bin then the shell will look for java in each of those directories in turn. The first one java command that it finds will be the one that is executed. You can find out which one it is by running this command.
which java
But that is not the end of it, because if you are using an OpenJDK Java installation on a typical Linux system, the java command in /usr/bin is actually the first in a chain of symlinks that is managed by the alternatives command. The actual executable is at the other end of the chain.
(The alternatives system is a way to implement a switchable system-wide default for a command or set of commands. Read the manual entry for more details. But note that Oracle Java installers (or RPMs) for Linux don't "grok" the Linux alternatives system ... one of my bugbears!)
Finally, it is common to see something like this in a shell "rc" file:
export JAVA_HOME=/path/to/jre # (or jdk)
export PATH=/bin:$JAVA_HOME/bin:/usr/bin:...
There is nothing magical about this. The $JAVA_HOME is going to be expanded by the shell before it sets the environment variable. Tthe actual PATH value will be:
/bin:/path/to/jre/bin:/usr/bin:...
So in summary:
echo $JAVA_HOME tells you the JRE or JDK that a typical 3rd-party tool will try to use by default.
java -version tells you the JRE or JDK that the java command comes from.
They may be different.
JAVA_HOME is an environment variable that contains the directory where Java is installed (if a few versions of Java are installed - this will point to the default)
java -version is a command that shows which version of Java is installed (and again, the one that's used by default in case a few versions are installed)
Addition: Thanks to Luiggi's comment: if the folder where java is installed is not in the PATH (another environment variable) - running java -version or any other java command will fail!
Its not related to jdk and JRE. java -version it is used by the java which is in /usr/bin/java. In some application is used $JDK_HOME. Both the jdks are same. Or we can define different jdk.
echo $JAVA_HOME
will print the value of environment variable called JAVA_HOME. If it's not set, it will print an empty message. Usually, you set JAVA_HOME to the path of the latest JDK installed in your pc.
java -version
will print the version of the java executable (Java Virtual Machine) that is set in your path, if configured. Otherwise, it will throw an exception on the command line.
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.
OS: Windows XP
I am using yuicompressor-2.4.2 to compress some CSS before uploading to my server.
But when I run it, the following exception appears:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/yahoo/platform/yui/compressor/Bootstrap (Unsupported major.minor version 48.0)
So I think it's because of the JRE.
I typed in the command:
cmd: java -version
And it says:
java version "1.3.1_01"
But it should say 1.6.0_16, since I have installed the latest version.
What should I do to make Java use the latest version instead of the old one?
Set the environment variable JAVA_HOME pointing to the directory where you have jdk 1.6.0
set JAVA_HOME=your_path_to_jdk1.6
set PATH=%JAVA_HOME%/bin;.;..;%PATH%
That's from a command window. Also you can do it from "My PC > Properties > Advanced > Environment variables"
Go to the system32 directory C:\Windows\System32 and delete following 3 files
java.exe
javaw.exe
javaws.exe
Now create a JAVA_HOME environment variable with value={root path of your jdk installation} and add the path till bin folder of your jdk in the PATH environment variable.
Open a fresh command prompt and run java -version to confirm the change
If you are using windows 7/10 go to command prompt and type
where java
Delete all the symbolic link shows below other than your actual installation directory.
Even if correctly added all the environment variables still sometime you can get wrong versions especially when you have multiple version installed in your system and want to switch between them.
On Windows, the JRE installs a java executable in the Windows directory, which should be the first java in your path. This is just a wrapper that looks in the Windows Registry to find the Java home directory (should be "%SystemDrive%\Program Files\Java\jre6" for Java 6) and runs using the libraries there.
Run %SystemRoot%\system32\java -version and see what you get. If that is Java 6, you have entries in your path before %SystemRoot%\system32 (which really should be first). Either fix your %PATH% variable, or you'll have to be explicit whenever you want to run this version of Java.
If running that instance of java doesn't report Java 6, its not installed (correctly). Uninstall and try installing again.
If you are having trouble because of the PATH, it is because you or some software you installed monkeyed with it; I recommend using the default which is to have system32 first. Everything works fine if the defaults are used.
Also, %JAVA_HOME% is not used by the JRE itself at all. Some common Java applications like tomcat and ant honor the %JAVA_HOME% setting, so perhaps yuicompressor does too. But this is a de facto convention, not a standard.
after where java in Command prompt
for example
where java
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-11.0.10\bin\java.exe
delete C:\Program Files\Common Files\Oracle folder
then close all terminals and write java -version in the terminal. it will show the right version
worked for me
You should modify your PATH environment variable:
My PC > Right click > properties > Advanced > Environment variables
And modify "Path"
Append at the end the path to your 1.6 installation:
;C:\jdk1.6.xxx\bin
and remove the previous one if present.
Add %JAVA_HOME%/bin to your PATH environment variable where JAVA_HOME is set to your JRE6u16 directory
I had the same problem. In System Properties > Environment Variables > System Variables > PATH make sure there is no other path associated with Java. To make sure, type in and check Java paths.
where java
Re-open Command Prompt and type java -version again. I hope this helps.
first by the following command, you should be aware of .exe file which runs when you type java in the command prompt
where java
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-11.0.10\bin\java.exe
as you see above , cmd first reads java from
C:\Program Files\Common Files\Oracle\Java\javapath
so go to the path above and remove java files .
then it should work fine
You should check your PATH environment variable. It is possible that some application you have installed has put its version of the jre in front of yours in the path.
It looks like the older Java version is still on the system PATH environment variable (where the OS looks for commands) or JAVA_HOME (where yuicompressor may look for the java executable)
How those variables are changed depends on your operating system.