如何在 MACOS 上将 Java 从 9 降级到 8。Eclipse 未与 Java 9 一起运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46513639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:23:56  来源:igfitidea点击:

How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9

javaeclipse

提问by LearningNew

How to downgrade Java from 9 to 8 on a macOS Sierra 10.12.6(16G29) . I tried removing the Java plugin and installed Java 8, however the Java and javac version shows 9 in terminal, but In system preferences it is 8. Thanks in advance!

如何在 macOS Sierra 10.12.6(16G29) 上将 Java 从 9 降级到 8。我尝试删除 Java 插件并安装 Java 8,但是 Java 和 javac 版本在终端中显示为 9,但在系统首选项中为 8。提前致谢!

回答by Lothar

The simplest solution might be to install Java 8 in parallel to Java 9 (if not still still existant) and specify the JVM to be used explicitly in eclipse.ini. You can find a description of this setting including a description how to find eclipse.inion a Mac at Eclipsepedia

最简单的解决方案可能是与 Java 9 并行安装 Java 8(如果还没有)并在eclipse.ini. 您可以eclipse.iniEclipsepedia上找到此设置的说明,包括如何在 Mac 上查找的说明

回答by mdeterman

You don't need to down grade. You can run more than one version of Java on MacOS. You can set the version of your terminal with this command in MacOS.

你不需要降级。您可以在 MacOS 上运行多个版本的 Java。您可以在 MacOS 中使用此命令设置终端的版本。

# List Java versions installed
/usr/libexec/java_home -V

# Java 11
export JAVA_HOME=$(/usr/libexec/java_home -v 11)

# Java 1.8
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

# Java 1.7
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)

# Java 1.6
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)

You can set the default value in the .bashrc, .profile, or .zprofile

您可以在 .bashrc、.profile 或 .zprofile 中设置默认值

回答by VK321

This is how I did it. You don't need to delete Java 9 or newer version.

我就是这样做的。您不需要删除 Java 9 或更新版本。

Step 1:Install Java 8

第 1 步:安装 Java 8

You can download Java 8 from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

您可以从这里下载 Java 8:http: //www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Step 2:After installation of Java 8. Confirm installation of all versions.Type the following command in your terminal.

第 2 步:安装 Java 8 后。确认安装所有版本。在终端中键入以下命令。

/usr/libexec/java_home -V

Step 3:Edit .bash_profile

第 3 步:编辑 .bash_profile

sudo nano ~/.bash_profile

Step 4:Add 1.8 as default. (Add below line to bash_profile file).

第 4 步:添加 1.8 作为默认值。(将下面的行添加到 bash_profile 文件中)。

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

Now Press CTRL+X to exit the bash. Press 'Y' to save changes.

现在按 CTRL+X 退出 bash。按“Y”保存更改。

Step 5:Reload bash_profile

第 5 步:重新加载 bash_profile

source ~/.bash_profile

Step 6:Confirm current version of Java

第 6 步:确认当前的 Java 版本

java -version

回答by Dan

Old question but just had that problem /dumb jira having problems with java 10/ and didn't find a simple answer here so just gonna leave it:

老问题,但刚刚遇到了这个问题 /dumb jira 有 java 10/ 的问题,在这里没有找到简单的答案,所以就离开它:

$ /usr/libexec/java_home -Vshows the versions installed and their locations so you can simply remove /Library/Java/JavaVirtualMachines/<the_version_you_want_to_remove>. Voila

$ /usr/libexec/java_home -V显示安装的版本及其位置,因此您可以简单地删除/Library/Java/JavaVirtualMachines/<the_version_you_want_to_remove>. 瞧

回答by Dorjee Dhondup

If you have multiple Java versions installed on your Mac, here's a quick way to switch the default version using Terminal. In this example, I am going to switch Java 10 to Java 8.

如果您的 Mac 上安装了多个 Java 版本,这里有一种使用终端切换默认版本的快速方法。在这个例子中,我将把 Java 10 切换到 Java 8。

$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    10.0.1, x86_64: "Java SE 10.0.1"    /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
    1.8.0_171, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

Then, in your .bash_profile add the following.

然后,在您的 .bash_profile 中添加以下内容。

# Java 8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home

Now if you try java -version again, you should see the version you want.

现在,如果您再次尝试 java -version,您应该会看到您想要的版本。

$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

回答by holosuda

You can remove "JavaAppletPlugin.plugin" found in Spotlight or Finder, then re-install downloaded Java 8.

您可以删除在 Spotlight 或 Finder 中找到的“JavaAppletPlugin.plugin”,然后重新安装下载的 Java 8。

This will simply solve your problem.

这将简单地解决您的问题。

回答by keshav

As it allows to install more than one version of java, I had install many 3 versions unknowingly but it was point to latest version "11.0.2"

由于它允许安装多个版本的 java,我在不知不觉中安装了许多 3 个版本,但它指向最新版本“11.0.2”

I could able to solve this issue with below steps to move to "1.8"

我可以通过以下步骤解决此问题以移至“1.8”

$java -version

openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9,混合模式)

cd /Library/Java/JavaVirtualMachines
ls

jdk1.8.0_201.jdk jdk1.8.0_202.jdk openjdk-11.0.2.jdk

jdk1.8.0_201.jdk jdk1.8.0_202.jdk openjdk-11.0.2.jdk

sudo rm -rf openjdk-11.0.2.jdk
sudo rm -rf jdk1.8.0_201.jdk
ls

jdk1.8.0_202.jdk

jdk1.8.0_202.jdk

java -version

java version "1.8.0_202-ea" Java(TM) SE Runtime Environment (build 1.8.0_202-ea-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.202-b03, mixed mode)

java 版本“1.8.0_202-ea”Java(TM) SE 运行时环境(构建 1.8.0_202-ea-b03)Java HotSpot(TM) 64 位服务器 VM(构建 25.202-b03,混合模式)