Search code examples
javapowershellcygwin

Cygwin runs different version of java than windows powershell


I have multiple versions of java installed. Recently while testing I noticed that cygwin and powershell were running different versions, and figured it was a problem with my path, but it looks to be something stranger. In powershell I get:

PS C:\Users\djpeaco> echo $env:JAVA_HOME
PS C:\Users\pavon> where.exe java
C:\Windows\System32\java.exe
PS C:\Users\pavon> C:\Windows\System32\java.exe -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

And then in cygwin (bash):

$ echo $JAVA_HOME

$ which java
/cygdrive/c/Windows/system32/java
$ /cygdrive/c/Windows/system32/java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode)

I tried restaring both shells, in case there was some environment change that one hadn't picked up, but that didn't solve the problem. Also, cmd.exe behaves the same as powershell. Does anyone know why running the exact same executable in cygwin vs powershell would end up running different JVMs?


Solution

  • Is Cygwin a 32-bit app? It's possible that, if Cygwin is 32-bit, the operating system is redirecting c:\windows\system32 (the real, 64-bit System32 folder) to c:\windows\syswow64 (the 32-bit System32 folder).

    Compare java.exe in c:\windows\system32 to java.exe in c:\windows\syswow64. They might be different.