Installing Oracle JDK on Windows subsystem for Linux

前端 未结 12 1968
半阙折子戏
半阙折子戏 2020-12-12 12:34

When trying to use the Linux version of Oracle\'s JDK on the latest Windows 10 build having support for bash, I am running into a problem with the prompt hanging whenever at

12条回答
  •  天命终不由人
    2020-12-12 13:19

    A lot of answers are recommending installing the Linux JDK even though they have a perfectly good Windows JDK. The beauty of WSL is preventing you from having to do things like this, as the file systems are interoperable. As long as you take the file extensions into account (outlined below), you would only have to install both for niche situations.

    Straightforward Method

    You can do this very simply by adding the following line of code to your .bashrc file, assuming that your Windows Environment variables are set correctly and WSL is installed:

    # Shared environment variables
    export JAVA_HOME=/mnt/d/Java/jdk11.0.4_10
    

    Just ensure that you change the directory to point to your JDK folder. In my case, it's in D:\Java\jdk11.0.4_10 which in WSL is /mnt/d/Java/jdk11.0.4_10

    Also, since you're using Windows binaries, you must specify the file type when running from a WSL bash shell:

    Example

    Calling Windows JDK from:

    CMD:

    javac MyClass.java
    java MyClass
    

    WSL:

    javac.exe MyClass.java
    java.exe MyClass
    

    Note WSL requires .exe since it is a Windows binary. When using the Linux distro of the OpenJDK, no extension is required..

提交回复
热议问题