1

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'
asked Jul 25, 2014 at 16:03
4
  • If you are on linux, try which java, the JAVA_HOME is override by that one I guess. Commented Jul 25, 2014 at 16:05
  • @DavidPostill I've looked at that post, it did not resolve my issue. Commented Jul 25, 2014 at 16:16
  • 1
    The Windows equivalent of what @flybird said is where java. Commented Jul 25, 2014 at 17:58
  • Since you are on win7 I guess, remove jdk8 & jre8 from control panel, remove the folder, reboot, then install java 8 again, this is just bad behavior of win7 & jdk8, Commented Jul 26, 2014 at 1:26

3 Answers 3

7

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.

answered Jul 25, 2014 at 21:38
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you that makes sense now. will try on monday!
1

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
Peter Lawrey
535k83 gold badges770 silver badges1.2k bronze badges
answered Jul 25, 2014 at 16:08

8 Comments

Not when I do java -version it is still looking for java 1.8 path, reports that it is unable to find it.
Updated the post. Please check.
Please add the output of 'echo %PATH%'. Also, is there a java.exe in system32?
@Zeus That suggests that Java 1.8 is not installed correctly. Was it deleted?
So it wasn't properly removed. Maybe you have more versions installed?
|
0

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.

answered Jul 25, 2014 at 20:57

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.