0

I have my path environment variable set to contain my Java 7 bin folder (C:\Program Files\Java\jdk1.7.0_55). Printing the path variable to the console indeed confirms that no other Java\bin folders are in it.

Still when I run the command java -version the printout is as follows:

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

In addition to Java 7, I also have Java 6 and Java 8 installed. All of the installations are JDKs with separate JREs also installed.

Why is Java 8 ran and not Java 7 in this case (by both, the old fashioned command prompt and Powershell)?

5
  • What happens if you change directory to "C:\Program Files\Java\jdk1.7.0_55\bin" and then do "java -version"? Maybe your old java got overwritten by the new version.
    – drkblog
    Commented Apr 28, 2014 at 11:30
  • @drk.com.ar CD'ing to the '<JDK7>\bin' dir and doing java -version prints out 'java version "1.7.0_55"', as expected. My guess is that there's something other than PATH that tells the command processor where to run stuff from. Perhaps something in the registry.
    – Kallja
    Commented Apr 28, 2014 at 15:45
  • I really don't think so. Console shell must honor the system variable PATH for finding an executable. Try putting "C:\Program Files\Java\jdk1.7.0_55\bin" as the first path in the variable. Make sure it is the first one by printing the PATH into the console and try again. If you didn't already do that. Take into account that PATH variable is a merge between user and system configuration.
    – drkblog
    Commented Apr 28, 2014 at 15:56
  • @drk.com.ar Adding the desired java dir as the first path entry helped. Put that as an answer and I'll accept it. Closer examination of the issue revealed that the Java 8 installer puts a java.exe file in <windir>\system32 directory, which is included in the path environment variable by default. I had the java dir as a user environment variable, which was overriden by the system wide variables, since they are considered first and user specific variables only after those.
    – Kallja
    Commented Apr 28, 2014 at 16:23
  • Done. The fact that Java 8 installer copied the java executable into the system directory is a huge violation of good practices for any installer.
    – drkblog
    Commented Apr 28, 2014 at 16:35

1 Answer 1

1

Console shell must honor the system variable PATH for finding an executable. Try putting "C:\Program Files\Java\jdk1.7.0_55\bin" as the first path in the variable. Make sure it is the first one by printing the PATH into the console and try again. If you didn't already do that. Take into account that PATH variable is a merge between user and system configuration.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .