ontherocks
ontherocks

Reputation: 1999

"which java" command in windows 7 returns weird path

As per the documentation here link

To find out which java executable the first one found in your PATH, execute:

which java

This command returns the following three paths in my machine

C:\>which java
C:\Windows\system32\java.EXE
C:\Program Files (x86)\Java\jre7\bin\java.EXE
C:\Windows\System32\java.EXE

There is no java.exe in C:\Windows\System32. I have java (Java SE 7 Update 25) installed in the location C:\Program Files (x86)\Java\jre7\ This is also confirmed by running "where java"

C:\>where java
C:\Program Files (x86)\Java\jre7\bin\java.exe

I have set Path=C:\Program Files (x86)\Java\jre7\bin; in environment variables. This path is not used in any environment variable.

What I want to know is, how and why does which java return C:\Windows\System32\java.EXE and that too twice?

Since there is no native which command in Windows, I just found out that a which.exe had been created to mimic "which" with the following script

@for %%a in (%PATH%) do @if exist %%a\%1 (
 for /f %%b in ('dir /b %%a\%1') do @echo %%a\%%b
)

@rem for %a in (%PATH%) do @if exist %a\which* dir /b /w %a\which*

Upvotes: 0

Views: 1586

Answers (3)

phasis
phasis

Reputation: 11

Your OS must be Windows 7 64-bit. And your jre and which command are 32-bit application. The 64-bit operating system uses the %SystemRoot%\system32 directory for its 64-bit library and executable files. This is done for backward compatibility reasons, as many legacy applications are hardcoded to use that path. When executing 32-bit applications, WoW64 transparently redirects 32-bit DLLs to %SystemRoot%\SysWoW64, which contains 32-bit libraries and executables. Therefore C:\Windows\system32\java.EXE for 32-bit application is actually C:\Windows\SysWoW64\java.EXE.

Upvotes: 1

T-Bull
T-Bull

Reputation: 2146

On my system, I have java.exe in C:\WINDOWS\system32, too. And javaw.exe and javaws.exe. Turns out, those are the exact same files that I have in C:\Program Files\Java\jdk7\bin. So it seems likely that the Java installer copied them to the system directory in order to prevent path issues.

Upvotes: 0

ssindelar
ssindelar

Reputation: 2843

The java.exe in system32 seems odd, but when you there is no java.exe its fine. What is even more strange that there is no "which" command on my Windows7, just where. It is possible that the "which" comes from some other path on PATH?

Upvotes: 1

Related Questions