I'm using a Windows .bat script and I set JAVA_HOME as C:/Program Files/Java/jdk1.6.0_32
when I do a java -version, it still shows the 1.3
How can I fix this? What am I doing wrong?
For me the issue was in my PATH variable, C:\ProgramData\Oracle\Java\javapath; was added by java windows install before my %JAVA_HOME%\bin;.
So I'd echo %JAVA_HOME% pointing to a JDK7 and java -version showing jdk8.
I'd to put %JAVA_HOME%\bin; before C:\ProgramData\Oracle\Java\javapath; so that java -version displays jdk7.
Try %JAVA_HOME%\bin\java -version
If you modify JAVA_HOME, it's usually better to invoke java with an absolute path (using JAVA_HOME) because the new binary is probably not in the path (and then Windows will load the wrong binary).
Make sure that the PATH environment variable is pointing to %JAVA_HOME%\bin.
Be sure not to mix the system variable path and the user variable system path. I feel OK in calling java without the absolute path (when I know how JAVA_HOME and PATH are configured).
Calling java -version from command line, causes cmd.exe to do the lookup on the "known" directories. "Known" means PATH environment variable. It seems that your PATH contains a java 1.3 bin folder, and not 1.6.
JAVA_HOME is another variable, that is used (for example, and not only) by java wrappers, or by scripts executing some java stuff.
Try doing this:
SET JAVA_HOME=C:/Program Files/Java/jdk1.6.0_32
%JAVA_HOME%/bin/java -version
Add quotes where needed.
I had similar issue,in my case , I had two versions java installed. it can be fixed by uninstalling one version of java completely from system.
Had a similar scenario today - two Windows 10 devices - both have JRE 1.6 & 1.7.
When typing
Java -version
One device shows 1.6 the other 1.7.
This was preventing me running a third party JAR to install some software on the device showing 1.6 (which worked fine on the device showing 1.7 when running java -version), using:
java -jar ThirdParty.jar
As the JAR needed to be run by 1.7.
Cause of this was in the PATH environment variable - one device had the location of 1.6 first in the PATH list, moving the 1.7 location above the 1.6 location resulted in consistency using Java -version and allowed me to install the software.
java -version will consult the paths in the special environment variable Path. You need to select the java version you want and move it upwards the latter (click "Move Up"). You probably have that reference to JDK 1.3 in Path above your addition of JDK 1.6. Since that's the first thing the OS finds, that's what it chooses to run.
Executing the command again with the same window opened after changing the environment variables will not work. Re-open it
I know this question is old but this was my case and I wanted to re-explain further, similar to #DanBot 's case
Related
I previously had Java 7 installed on my Windows PC. System environment variable also had location to it. I installed Java 10 without uninstalling 7 or changing the environment variable. Now when I go to CMD or Cygwin and enter Java -version it says Java 10.
I would think since I didn't change the environment variable that it would still be 7. How is Windows deciding what JDK to use?
Thanks!
Probably your JAVA_HOME or just PATH environment variables were changed.
Go to command line and do the following to check it:
> echo %JAVA_HOME%
For example, for me it gives back:
C:\Program Files\Java\jdk-9.0.4
How is Windows deciding what JDK to use?
Windows is NOT making decisions on its own. If you get version 10 information when you run java -version, it is because Windows is finding the folder containing java.exe corresponding to the version 10 first in the paths pointed to by the PATH environment variable. If you have installed Java using an installer, the installer would update the PATH variable for you. Check your PATH variable and you will see the Java 10 folder appearing there first and then Java 7 folder.
If you are using a java ide , you might find the location in JRE configurations. for example in eclipse :
windows > preferences > Installed JREs
.
Your JAVA_HOME variable might still be set to JDK 7 directory, however the Java 10 installation may have inserted it's /bin directory to the PATH.
Check to ensure that java 10 isn't on the PATH before java 7, or hasn't overwritten it.
CMD etc. check the path for the binaries for commands like java-version.
I just updated to IntelliJ IDEA 16 which comes with Java JDK 1.8. Fyi, I had downloaded Java JDK 1.8 a long time ago.
I tried to run my plugin that I am developing, and I cannot even do that, I get the following error message (slightly condensed)
"C:\Program Files\Java\jdk1.7.0_45\bin\java" -Xmx512m -Xms256m -XX:MaxPermSize=250m -ea "-Xbootclasspath/a:C:/Program Files (x86)/JetBrains/IntelliJ IDEA Community Edition 144.3143.6\lib\boot.jar" -Didea.config.path=C:\Users\Christopher.IdeaIC14\system\plugins-sandbox\config - ... -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.7.0_45\lib\tools.jar; ... ;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 144.3143.6\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.intellij.idea.Main
Unsupported Java Version: Cannot start under Java 1.7.0_45-b18: Java 1.8 or later is required.
So, I clearly know what the problem is; however, I cannot seem to figure out where the location to fix this is.
I have tried a lot of things so far; most involve using the search box in Settings and switching whatever I could to version 1.8. Also, I had updated my Environment Variable for Java from 1.6 to 1.8
With all of these changes, nothing is working! So how do I go about fixing this seemingly simple issue?
Set IDEA_JDK (or IDEA_JDK_64) environment variable.
Check Selecting the JDK version the IDE will run under
TL;DR --> Set JAVA_HOME to C:\Program Files\Java\jdk1.8.0_51
Java 8 is required to run IntelliJ IDEA starting from version 16 on all the supported platforms.
The actual JDK version used by the IDE can be verified in Help | About dialog (open any project to access the menu).
idea64.exe uses this JDK search in the following sequence:
IDEA_JDK_64 environment variable
..\jre64 directory
system Registry
JDK_HOME environment variable
JAVA_HOME environment variable
Under Arch Linux you can simply set java 8 as default (you must have it installed):
$ sudo archlinux-java set java-8-openjdk
In case anyone arrives here and hasn't had any luck with the other solutions, try this. I'm using PhpStorm under OSX, but the steps are probably applicable to JetBrains' other IDEs too:
Navigate to your IDE's config folder (see this article to learn how to find this folder's location).
Open the idea.propeties file.
If a JVMVersion attribute exists, delete that entire entry. If it doesn't exist, then this probably won't be of much help!
Save the file.
Launch your IDE.
Just set JAVA_HOME system variable to your JDK 8:
Run in cmd
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_111"
don't foget to change to your java path
In my case, Ubuntu 14 (32-bit), I opened the file:
/home/<user>/Programs/PhpStorm/bin/phpstorm.sh
and after
if [ "$JDK" = "" ] && [ "$OS_TYPE" = "Linux" ] && ........... fi
I added:
if [ "$JDK" = "" ]; then
JDK="/usr/lib/jvm/java-8-oracle"
fi
And then it works!
Double check that your JAVA_HOME points to the correct 1.8 Installation and make sure that in the PATH env there is no reference to "C:\Program Files\Java\jdk1.7.0_45\bin".
Try to print your JAVA_HOME/PATH from the Console and see what the output is. If your changes are not reflected logout and then login again.
IntelliJ 16 REQUIRES Java 8 to run, it won't run under Java 7. It's compiled to Java 8 classes so it can't ever be run on an older JVM.
This is well and clearly mentioned in the documentation.
So if you have your system JVM be an older one, it will fail to start unless you coerce it into using a non-default JVM.
Possibly you have some java related executables left over in your Windows/System32 directory, where some older Java installers would drop them. Delete these by hand from the file system and see what happens.
Just in case this page needs one more recommendation, I fixed the problem in my case by going to the IDE's config folder (as #Nate puts it, see here for how to locate it), and deleting the idea.jdk file (which held a reference to a 1.6 VM).
Apart from setting the correct Java version for the global, per project and per module SDK, for the Java Compiler, and for the language level, you also must set the Target bytecode version both for the project and (if you use maven) for each maven module.
Often the project bytecode version is correct but the module bytecode version is lower, i.e. 1.5.
The per-module bytecode version is not displayed when opening the default preferences via File > Other Settings > Default Settings. You must edit the current preferences either via a shortcut (i.e. ⌘+,) or from the main menu as shown below (for mac):
I had the same problem. All paths pointing to java jdk 8, but still throwing the error. I was able to run Android Studio by running the "studio64.exe" instead "studio.exe" in the bin folder
I am trying to run a compiled java class and getting errors but when I checked my java environments it points to different version.
Javac –version gives me 1.8.0
And
Java –version gives me 1.6.2
The Java_home and path is pointing to the 1.8 version.
Please help.
Java installation under Windows is sometimes a really severe source of pain. The following assumes that you have Windows:
Check your path variable
Check JAVA_HOME variable
Newer versions of Java (1.6 ?, but 1.7 and 1.8) copy some Java executables into the System32 directory of the windows installation. Simply delete this files (or move them somewhere else for easy recovery)
running java applications by using .bat files a specific JDK / JRE can be provided.
There may be more sources of your problem. For example with Maven you depend on JAVA_HOME, with Eclipse you have the project settings, ...
Please check the following :
1) Check your path variable
2) Check JAVA_HOME variable
3)Delete the java,javaw and javaws .exe file from the system32 folder
java.exe while java installation gets copied under System32 directory. Also we tend to append java path in the end of the path variable. This causes running java command pointing to the one in System32 (it takes the first path value that is encountered and ignores rest, in this case java of system32 folder). And when it cannot find javac it looks to other values of path and finds it towards the end for the java JDK (this is the one you want to use).To overcome this problem give path to your JDK for example C:\ProgramData\Oracle\Java\bin as the first entry in the windows path variables. Even before your system32 entry. This ensures you point to only one java. My path entry looks something like this:-
%JAVA_HOME%\bin;%SystemRoot%\system32;
If you are running Windows, you could perhaps check the path environment variable. It might point to an older JRE installation.
One possibility is that your Java link is inconsistent. Go to this location (Windows):
C:\ProgramData\Oracle\Java\javapath and check where to does java.exe point.
In case it is not up-to-date consider fixing it with:
mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\<your JDK>\bin\"
(you may need to remove javapath old link before you create a new one)
I have multiple versions of Java installed in the environment(I know it is bad). I've set the JAVA_HOME to jdk 1_4 directory. This is not installed, but extracted from zip and placed it somewhere. We have java 1.8 JRE also installed in the system. I never set the path to this installed directory. Now i'm trying to run some ant script that depends on jdk 1_4. I get some exception saying that it is not able to find tools.jar in java1.8... .
My question is that when the path and java_home are set to jdk 14 why does the ant look for 1.8 version of java? I'm confused.
Update: I have looked up the duplicate issue.
Additional details: Java -version prints 1.8 with jdk 14 in the path and java_home. I uninstalled 1.8. reopened cmd tried java -version, now it errors out saying that it is not able to find java1.8 instead of trying to find the next java available in the path or java_home.
Error shown:
C:\Users\usrpao>java
Error: could not open `C:\Program Files\Java\jre8\lib\amd64\jvm.cfg'
I have multiple versions of Java installed in the environment(I know it is bad). I've set the JAVA_HOME to jdk 1_4 directory.
Not wrong at all. I have a similar setup because I have to switch between Java version.
First, install Java JDKs in the root of your drive. No spaces in the directory names. For example, C:\Java\Java-1.6-21 and C:\Java\Java-1.7-5.
In your Environment Variables section in your System Control Panel (under Advance), create an environment variable to point to each one of these Java Home directories. For example, JAVA_HOME_17 = C:\Java\Java-1.7.5 and JAVA_HOME_16 = C:\Java\Java-1.6-21. This should be a System Environment variable.
Create a JAVA_HOME environment variable that points to the Java version you want: JAVA_HOME = %JAVA_HOME_17%.
Now in the System PATH, prefix the PATH (the very first entry) with %JAVA_HOME%\bin.
When you open a console window, your default java and javac commands will be the correct Java version.
If you need to change a version, change the JAVA_HOME environment variable to point to the correct environment variable and open a new console window. Now that new Java will be in your path.
NOTE: It is vitally important that %JAVA_HOME%\bin is in the first part of your PATH before C:\Windows\System32. You don't want the java.exe that exists in that directory to be your default java.
You haven't specified the operating system, so:
on windows, java installs a java.exe in C:\Windows\system32, which is probably on the path before java_home, and so gets picked up
on Linux, various distributions that support multiple installed java versions will also have some symlink earlier on the path. Run 'which java' to determine where that symlink is
Multiple java versions in the system is the problem, I uninstalled all the java versions first. Restarted my machine. Path and java home points to the jdk 1.4. java -version now points to the version specified in the path. Thanks all.
I am having a problem running Ant with JDK 1.6 on Mac OS X. Even though Java application versions is set to Java SE 6 in OS X's Java Preference, executing java -version in Terminal also shows java version "1.6.0_07", Ant still seems to use JDK 1.5 to be using JDK 1.5 as it does not see JDK 1.6 classes when compiling my code.
I understand that Ant relies on JAVA_HOME environment variable to specify which JDK to use. However, I do not quite understand how this variable can be set on Mac OS X.
Hence, my question is how to make Ant runs with JDK 1.6 on Mac OS X. If the correct way is still to set JAVA_HOME environment variable, how to set the variable on OS X.
The JAVA_HOME environment variable is set in your home directory's .profile file. (/Users/ejel/.profile ?) Edit it and set it to what you want it to be. E.g.:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
From this point onward, every time you open a new terminal window it will have JAVA_HOME set to this new value. It will not have changed with any existing open windows.
If you are truly aghast to putting this in the profile, or if it conflicts with other software, the export statement could always be run in the terminal manually or go into a script (eg: setj6ev.sh) that is run once before you start running ant tasks.
I've added the line
export JAVA_HOME=`/usr/libexec/java_home`
To my .zshrc file, it seems to do the trick (.bash_profile or whatever if you use bash).
Ted, using the Java Preferences app doesn't change the CurrentJDK symlink in /System/Library/Frameworks/JavaVM.framework/Versions, which is what Ant will use if the JAVA_HOME environment variable isn't set. Thus, you can either change that symlink manually or set the JAVA_HOME environment variable, but if you do neither, then Ant won't use the correct JDK.
You can see the version of the jdk that Ant is using by issuing an <echo message="${ant.java.version}"/> in your build.xml file.
Explicitly setting the JAVA_HOME variable in your .profile/.bashrc/.zshrc isn't actually the recommended way to do it on the mac. There are programs that I've seen get hosed up with an explicitly set JAVA_HOME to a particular version (grails 1.1 with some spring resources for example).
The correct way to set the version of Java that you want to use is to use the /Application/Utilities/Java Preferences.app application.
In there, you drag the version of java that you want to use to the top. This will enable that version for all applications (both those run from the command line and those launched through GUI processes).
You can test the current version by running this from the command line:
java -version
I don't actually like the way that the mac handles the entire set of java symlinked directories and files. It's not obvious and people often screw it up.
See the apple developer page on this for more details.
I try everything, and only one thing works for me : unlink CurrentJDK, and link to 1.6 :
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo unlink CurrentJDK
sudo ln -sF "1.6" CurrentJDK
Finally I get :
java -version
java version "1.6.0_22"
I hope this help.
You may need to open a new command prompt instance so that the shell can pick up any changes to the environment variables.