How to use the windows installation of java from BashOnWindows10?

10

1

I'm not able to run the windows version of java.exe from BashOnWindows10. It is present in PATH, but the invocation fails silently. My goal is to avoid having to install the JDK/JRE again in WSL. As I'm running the Creator's update, I was was expecting the to be able to invoke any windows application. Any ideas why this is happening? I'm however able to launch the windows installation of Python successfully.

bash

username@PC:~$ which java.exe
/mnt/c/ProgramData/Oracle/Java/javapath/java.exe

username@PC:~$ java.exe
username@PC:~$         <<<nothing happens

username@PC:~$ which python.exe
/mnt/c/Python34/python.exe

username@PC:~$ python.exe
Unable to translate current working directory. Using C:\WINDOWS\system32
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

cmd.exe

C:\Users\username>java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

Abhiram

Posted 2017-06-05T16:30:02.697

Reputation: 191

It is not related to Java, it is a problem with all Windows binaries. See this bug for discussion and some work arounds: https://github.com/Microsoft/BashOnWindows/issues/333

– eckes – 2017-06-05T16:52:44.917

Answers

2

This issue is because WSL does not support windows shortcuts in the Creator's update. /mnt/c/ProgramData/Oracle/Java/javapath/java.exe is actually a shortcut to the actual installation directory which is C:\Program Files\Java\jre1.8.0_31\bin in my case. Invoking java from the actual installation path seems to work as expected.

This issue is resolved in build 16193

Abhiram

Posted 2017-06-05T16:30:02.697

Reputation: 191

7

Here's how I just made Java "just work" for my WSL installation.

ln -s /mnt/c/Program\ Files\ \(x86\)/Java/jre1.8.0_151/bin/java.exe /bin/java

What this does is create a symbolic link in your /bin folder to your Windows Java binary. Whenever WSL tries to invoke Java now, it's redirected to the Windows version. You will probably need to adjust the path as Java versions change in the future.

detuur

Posted 2017-06-05T16:30:02.697

Reputation: 171

Superb! Before: Java -version gives Command 'Java' not found After: Java - version gives java version "1.8.0_151" I wish I could up this answer like 10 points instead of 1! – boardtc – 2018-11-07T14:53:37.737

1Just a heads up that this will "confuse" and paths used in your Java program or as properties/inputs. E.g. "/tmp/somefile.txt" will be e.g. "c:/tmp/somefile.txt" when your Windows Java tries to execute it and result in file not found! – Anders – 2019-05-31T09:08:31.047

0

If you want to execute your java.exe inside the linux subsystem you can follow this answer: https://stackoverflow.com/a/54151117/2751561

If wat you want the other way around you can call the java bin on cmd like this:

wsl java -version

ViniciusCR

Posted 2017-06-05T16:30:02.697

Reputation: 1