在适用于Linux的Windows子系统上安装Oracle JDK [英] Installing Oracle JDK on Windows subsystem for Linux

查看:251
本文介绍了在适用于Linux的Windows子系统上安装Oracle JDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试在支持bash的最新Windows 10版本上使用Linux版本的Oracle JDK时,每当尝试调用 java 二元。

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 attempting to invoke the java binary.

键入甚至像 java -version 这样简单的东西挂起,我必须终止进程恢复控制。

Typing even something as simple as java -version hangs and I have to terminate the process to resume control.

任何人都可以使用它吗?

Anyone got this working yet?

推荐答案

我想澄清一下,截至2016年12月9日,您肯定可以在Ubuntu Bash for Windows 10上安装Java 8,并且@Karl Horton是正确的。

I wanted to clarify that as of 9 December 2016, you most certainly can install Java 8 on Ubuntu Bash for Windows 10 and that @Karl Horton is correct.

您需要安装解压缩 sudo apt-get install unzip

将此脚本复制到您的某个位置bash for windows session并使其可执行(chmod + x filename)。如果你不使用基于命令行的编辑器(如vim),那么你将有windows行结尾来处理。您可以使用dos2unix或您首选的处理方式。我只是使用vim将其粘贴到一个文件中。

Copy this script somewhere in your bash for windows session and make it executable (chmod +x filename). If you do not use a command line based editor such as vim then you will have windows line endings to deal with. you can use dos2unix or your preferred way of dealing with that. I just paste it into a file using vim.

 #!/bin/bash

set -ex

# UPDATE THESE URLs
export JDK_URL=http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
export UNLIMITED_STRENGTH_URL=http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip

# Download Oracle Java 8 accepting the license
wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
${JDK_URL}
# Extract the archive
tar -xzvf jdk-*.tar.gz
# clean up the tar
rm -fr jdk-*.tar.gz
# mk the jvm dir
sudo mkdir -p /usr/lib/jvm
# move the server jre
sudo mv jdk1.8* /usr/lib/jvm/oracle_jdk8

# install unlimited strength policy
wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
${UNLIMITED_STRENGTH_URL}
unzip jce_policy-8.zip
mv UnlimitedJCEPolicyJDK8/local_policy.jar /usr/lib/jvm/oracle_jdk8/jre/lib/security/
mv UnlimitedJCEPolicyJDK8/US_export_policy.jar /usr/lib/jvm/oracle_jdk8/jre/lib/security/

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/oracle_jdk8/jre/bin/java 2000
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/oracle_jdk8/bin/javac 2000

sudo echo "export J2SDKDIR=/usr/lib/jvm/oracle_jdk8
export J2REDIR=/usr/lib/jvm/oracle_jdk8/jre
export PATH=$PATH:/usr/lib/jvm/oracle_jdk8/bin:/usr/lib/jvm/oracle_jdk8/db/bin:/usr/lib/jvm/oracle_jdk8/jre/bin
export JAVA_HOME=/usr/lib/jvm/oracle_jdk8
export DERBY_HOME=/usr/lib/jvm/oracle_jdk8/db" | sudo tee -a /etc/profile.d/oraclejdk.sh

现在我可以做以下事情

fieldju@DESKTOP-LTL6MIC:~$ java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)                                                

上述脚本中的链接和版本可能在您阅读本文时已过期,因此请转到 http://www.oracle.com/technetwork/java/javase/downloads/index.html 接受许可证,以便他们的js允许您复制新的URL,你应该很高兴。

The links and versions in the above script are likely to be out of date by the time you read this, so just head over to http://www.oracle.com/technetwork/java/javase/downloads/index.html accept the license so that their js lets you copy the new URLs and you should be good to go.

这篇关于在适用于Linux的Windows子系统上安装Oracle JDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆