OS X 中的 Eclipse 使用与 CLI 不同的 Java 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24598465/
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
Eclipse in OS X uses different version of Java than CLI
提问by Jamie Clinton
When I type java -version
in the console I get java version "1.8.0_05"
. The soft link /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
points to /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents
. In the java preferences window, the only listed version of Java is 1.8. JAVA_HOME is set to /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
.
当我java -version
在控制台中输入时,我得到java version "1.8.0_05"
. 软链接/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
指向/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents
. 在 Java 首选项窗口中,唯一列出的 Java 版本是 1.8。JAVA_HOME 设置为/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
.
However, when I try to run Eclipse.app, I get the error: Version 1.6.0_65 of the JVM is not suitable for this product. Version: 1.7 or greater required.
但是,当我尝试运行 Eclipse.app 时,出现错误: Version 1.6.0_65 of the JVM is not suitable for this product. Version: 1.7 or greater required.
I believe it is trying to use /System/Library/Java/JavaVirtualMachines
and in that directory the only version is 1.6.0.jdk
.
我相信它正在尝试使用,/System/Library/Java/JavaVirtualMachines
并且在该目录中唯一的版本是1.6.0.jdk
.
How can I get eclipse to use the correct version of Java?
如何让 Eclipse 使用正确版本的 Java?
采纳答案by Thorbj?rn Ravn Andersen
Download the 64-bit version of Eclipse instead of the 32-bit version.
下载 64 位版本的 Eclipse 而不是 32 位版本。
The reason is that Eclipse contains native machine code (for the GUI) which is why there is both a 32-bit and 64-bit version of Eclipse, and this explicitly require the corresponding Java version. Originally Apple created both versions up to Java 6, but Oracle only creates a 64-bit version (much to the dismay of owners of older machines). So, if you download a 32-bit version of Eclipse it will only run with an Apple JVM, which apparently is too old (which surprise me - I thought Java 6 was still supported for Eclipse 4.4)
原因是 Eclipse 包含本地机器代码(用于 GUI),这就是为什么有 32 位和 64 位版本的 Eclipse,并且这明确要求相应的 Java 版本。最初,Apple 创建了 Java 6 之前的两个版本,但 Oracle 只创建了 64 位版本(这让旧机器的所有者非常沮丧)。因此,如果您下载 32 位版本的 Eclipse,它将只能与 Apple JVM 一起运行,这显然太旧了(这让我感到惊讶 - 我认为 Eclipse 4.4 仍然支持 Java 6)
回答by atamanroman
Try adding the following lines to your eclipse.ini
:
尝试将以下行添加到您的eclipse.ini
:
-vm
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
Maybe a newer version of eclipse could help, too (if yours is out of date).
也许较新版本的 eclipse 也有帮助(如果您的版本已过时)。
回答by Alexandre Santos
Take a look in your System Preferences
-> Java
. It should open the Java Control Panel
. In the panel, check if you have one (or many) JDKs.
看看你的System Preferences
-> Java
。它应该打开Java Control Panel
. 在面板中,检查您是否有一个(或多个)JDK。
I suspect you have many and are setting the JDK in your .profile
while Eclipse is reading some other Java Home.
我怀疑您有很多并且正在您的 JDK 中设置 JDK,.profile
而 Eclipse 正在阅读其他一些 Java Home。
You can change them manually by running this in your terminal
您可以通过在终端中运行它来手动更改它们
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
To check if it worked, run java -version
and you should see something like
要检查它是否有效,运行java -version
,你应该看到类似的东西
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
Try calling Eclipse now from the command line. To call Eclipse as an App, just set the Java8 through the Java Control Panel
. This will be read when Eclipse starts.
现在尝试从命令行调用 Eclipse。要将 Eclipse 作为 App 调用,只需通过Java Control Panel
. 这将在 Eclipse 启动时读取。
This is what I have on my Java Control Panel
:
这是我的Java Control Panel
:
This is on my Eclipse Luna:
这是在我的 Eclipse Luna 上:
回答by Jamie Clinton
Download the 64-bit version of Eclipse.
Download the 64-bit version of Eclipse.
This solved the problem. Thanks everyone.
这解决了问题。谢谢大家。
回答by Rem Morales
I solved this issue in my mac with yosemite:
我在我的 mac 上用 Yosemite 解决了这个问题:
- Installed JDK for MACOSX 64bits from https://jdk8.java.net/download.html
- Inside the eclipse.ini I put this line:
-vm /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
- 从https://jdk8.java.net/download.html为 MACOSX 64 位安装 JDK
- 在 eclipse.ini 里面我放了这行:
-vm /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
And it worked for me!
它对我有用!
回答by Muhammad
I faced this same problem but rather than making it to use version 1.8 I changed the settings in eclipse.ini
file so I can just run the program regardless which version of jvm does it want to use
我遇到了同样的问题,但我没有让它使用 1.8 版,而是更改了eclipse.ini
文件中的设置,这样我就可以运行该程序,而不管它想使用哪个版本的 jvm
Solution:
解决方案:
Open the directory where you have Eclipsecopy in your computer.
打开计算机中Eclipse副本所在的目录。
You would see a file name eclipse
press control
key and click
on it to see the options.
您会看到一个文件名,eclipse
按下control
键并click
在其上查看选项。
Then click on Show Original
from the options, there you would find eclipse.ini
file open it with a text editor and change the -Dosgi.requiredJavaVersion=1.7
to -Dosgi.requiredJavaVersion=1.6
然后Show Original
从选项中单击,在那里你会发现eclipse.ini
文件用文本编辑器打开并将其更改-Dosgi.requiredJavaVersion=1.7
为-Dosgi.requiredJavaVersion=1.6
Save the file and open the ecplise.app
it should open now without any error
保存文件并打开ecplise.app
它现在应该打开没有任何错误