JAVA_HOME environment variable and Java JDK fun - java

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

Related

How to change the current java version through environment variables?

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.

IntelliJ IDEA 2016.1(64) : Unsupported java version Cannot start under Java 1.7.0_79-b15: Java 1.8 or later is required

Currently I set JAVA_HOME environment variable to 1.7
When I try to open the file idea64.exe (path : ..\JetBrains\IntelliJ IDEA 2016.1\bin\idea64.exe) below error is populated
Unsupported java version
Cannot start under Java 1.7.0_79-b15: Java 1.8 or later is required.
From the above error I understood that I have to set my JAVA_HOME to 1.8, but I don't want to set JAVA_HOME to 1.8.
I believe there should be a configuration file where in I can point to Java-8 and fix this, can anyone please let me know where can I do the configuration changes?
You should create IDEA_JDK_64 environment variable and set its value to JDK8 instance location on your computer.
This JDK8 instance can be used only for idea and JAVA_HOME can point to the Java 7 at the same time without any problems.
Via documentation:
idea64.exe uses this JDK search sequence:
IDEA_JDK_64 environment variable
..\jre64 directory
system Registry
JDK_HOME environment variable
JAVA_HOME environment variable
Creating the IDEA_JDK_64 environment variable pointing to the current JDK 8 installation didn't work for me on Windows 7.
What worked was starting IDEA from its script residing in:
<your location of>\IntelliJ IDEA Community Edition 2016.1.1\bin\idea.bat
On Windows, one can map a shortcut to that location and change its icon to:
<your location of>\IntelliJ IDEA Community Edition 2016.1.1\bin\idea.ico
i found answers above a bit unclear being new to this.
your first step would be to open environment variables, search in windows.
in user variables create a new entry for IDEA_JDK_64
add the path to the JDK version you wish to use, for me it was C:\Program Files\Java\jdk-13.0.1
this should do the job.
first : jdk -version ?? 1.7 or 1.8 ,so change this environment variable;
then : uninstall idea
;end : install idea
this is a stupid method ,but it works!
Maybe you open IDEA with idea64.exe, try idea.exe.

Setting Environment variable in Linux

I am using Maven for my project and I need to set environment variables in my system for it to work. I have set environment variable for maven but it also requires setting up Java environment variable. I am accessing linux through Putty through a remote server. I tried setting up JAVA_HOME environment variable but I get this error:
Error: JAVA_HOME is not defined correctly.We cannot execute /home/z222189/jdk1.8.0_31/jre/bin/java
I used export JAVA_HOME=/home/z222189/jdk1.8.0_31/jre for this purpose
Even when i try to execute the java.exe file directlty in linux I get error
-bash: ./java.exe: cannot execute binary file
Any suggestions on how to resolve this issue?
You shouldn't refer to the jre/ subfolder, as Maven will need a Java compiler and potentially other JDK-only tools.
So just use:
JAVA_HOME=/home/z222189/jdk1.8.0_31
EDIT: (making sure that a correct, working JDK is installed at that location, of course...)
Seems you are in Linux, be sure you get Java for Linux!
Set JAVA_HOME using
export JAVA_HOME=/home/z222189/jdk1.8.0_31
Does not work because java is not there, or the version is not the correct, if you already installed correct java linux version and you dont really know where your oracle-java is installed, you can find this running
which java
which will tell you which binary of java is being called, normally is something like
/usr/bin/java
but you can
readlink -f /usr/bin/java
that will give you something like
/usr/lib/jvm/java-7-oracle/jre/bin/java
ergo
export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/

Weird issue with environment variables

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.

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.

Categories