Java 8 与 Java 1.8 安装(目录名称)

Java 8 与 Java 1.8 安装(目录名称)

不知何故,我在 Ubuntu 16.04 系统上最终得到了两个 OpenJdk 8 目录:

  1. /usr/lib/jvm/java-8-openjdk-amd64
  2. /usr/lib/jvm/java-1.8.0-openjdk-amd64

问题是第一个目录似乎已损坏。如果我/usr/lib/jvm/java-8-openjdk-amd64/bin/java HelloWorld对现有HelloWorld.class文件执行此操作,则不会得到任何结果,但执行此操作/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java HelloWorld会产生预期的输出。

现在看看这个:

core$ ll /etc/alternatives/jav*
lrwxrwxrwx 1 root root 42 Nov  7 11:02 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/bin/java*
lrwxrwxrwx 1 root root 52 Nov  2 19:32 /etc/alternatives/java.1.gz -> /usr/lib/jvm/java-9-openjdk-amd64/man/man1/java.1.gz
lrwxrwxrwx 1 root root 43 Nov  2 19:35 /etc/alternatives/javac -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javac*
lrwxrwxrwx 1 root root 53 Nov  2 19:35 /etc/alternatives/javac.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javac.1.gz
lrwxrwxrwx 1 root root 45 Nov  2 19:35 /etc/alternatives/javadoc -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javadoc*
lrwxrwxrwx 1 root root 55 Nov  2 19:35 /etc/alternatives/javadoc.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javadoc.1.gz
lrwxrwxrwx 1 root root 43 Nov  2 19:35 /etc/alternatives/javah -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javah*
lrwxrwxrwx 1 root root 53 Nov  2 19:35 /etc/alternatives/javah.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javah.1.gz
lrwxrwxrwx 1 root root 43 Nov  2 19:35 /etc/alternatives/javap -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javap*
lrwxrwxrwx 1 root root 53 Nov  2 19:35 /etc/alternatives/javap.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javap.1.gz

所有这些都指向8目录,而不是1.8,这在运行程序时会导致问题。我的问题是:这种混乱是怎么发生的,解决这个问题的最佳方法是什么?我想删除其他所有内容,并将 OpenJDK 8 作为我的默认 JDK。

答案1

选择 Java 版本:

sudo update-alternatives --config java

示例输出:

There are 2 choices for the alternative java (providing usr/bin/java).         
Selection     Path                                            Priority  Status
------------------------------------------------------------
  0           /usr/lib/jvm/java-8-oracle/jre/bin/java          1081     auto mode
  1           /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081     manual mode
* 2           /usr/lib/jvm/java-8-oracle/jre/bin/java          1081     manual mode

Press <enter> to keep the current choice[*], or type selection number: 

您还可以通过使用以下选项来查看java的替代方案:javac--list

sudo update-alternatives --list java
sudo update-alternatives --list javac

答案2

好吧,我的情况是,我在不知情的情况下也安装了 openjdk headless,因此最终安装了两次。我最终从系统中删除了所有 jdk,并安装了 JDK 9(我得说,这不是一个没有问题的安装!)现在一切似乎都解决了!

相关内容