Reputation: 6566
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'
Upvotes: 1
Views: 7608
Reputation: 107030
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.
C:\Java\Java-1.6-21
and C:\Java\Java-1.7-5
.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.JAVA_HOME = %JAVA_HOME_17%
.%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.
Upvotes: 7
Reputation: 6566
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.
Upvotes: 0
Reputation: 24192
You haven't specified the operating system, so:
Upvotes: 1