如何使用不同的 Java 版本运行 Eclipse?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18469170/
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 01:52:52  来源:igfitidea点击:

How to run Eclipse with different Java version?

eclipsejava

提问by Johny Jaz

I am using Eclipse for developing BlackBerry Applications. I have JDK/JRE 7 currently on my computer, but that makes the BlackBerry plugins crash. Actually is a known issue and the only thing need to be done is run Eclipse with JDK/JRE 6 instead of 7.

我正在使用 Eclipse 开发 BlackBerry 应用程序。我的计算机上目前有 JDK/JRE 7,但这会使 BlackBerry 插件崩溃。实际上是一个已知问题,唯一需要做的就是使用 JDK/JRE 6 而不是 7 运行 Eclipse。

I downloaded and installed version 6. However I am pretty sure Eclipse still uses 7. I had the same problem a year ago and I remembered I had to configure some System Variables and it worked, but I can't really find the solution now.

我下载并安装了版本 6。但是我很确定 Eclipse 仍然使用 7。一年前我遇到了同样的问题,我记得我必须配置一些系统变量并且它工作,但我现在找不到解决方案。

Any idea on this one? Important! I don't want to compile in version 6, which means I just have to choose the Java version throughEclipse. What I need is Eclipse to startwith version 6.

对这个有什么想法吗?重要的!我不想在版本 6 中编译,这意味着我只需要通过Eclipse选择 Java 版本。我需要的是 Eclipsestart版本 6。

回答by PbxMan

If you want to make sure you are running you java apps in Windows 7with an specific java version:

如果您想确保在Windows 7 中使用特定的 Java 版本运行 Java 应用程序:

1 - Check out what which version is running by default.Run cmd to go to the console and type: java -version

1 -检查默认情况下运行的是哪个版本。运行 cmd 进入控制台并输入:java -version

C:>java -version

java version "1.6.0_45" Java(TM) SE Runtime Environment (build 1.6.0_45-b06) Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)

C:>java -version

java version "1.6.0_45" Java(TM) SE Runtime Environment (build 1.6.0_45-b06) Java HotSpot(TM) Client VM(build 20.45-b01,混合模式,共享)

2 - Change the default jdk by changing the path. Example here. Make sure you java.exe from your desired jdk is before any other java.exe from any other JDK in the path. ex. in JDK 1.6 you java.exe should be here C:\java\jdk1.6\bin\java.exe.

2 -通过更改路径来更改默认 jdk。示例在这里。确保来自所需 jdk 的 java.exe 位于路径中来自任何其他 JDK 的任何其他 java.exe 之前。前任。在 JDK 1.6 中,你的 java.exe 应该在 C:\java\jdk1.6\bin\java.exe。

Once you have changed the path, open a new console and verify again which jdk version you are running.

更改路径后,打开一个新控制台并再次验证您正在运行的 jdk 版本。

3 - Make sure in eclipse.iniparam -vmanother jre version is not set.

3 -确保在eclipse.iniparam -vm中没有设置另一个 jre 版本。

回答by Ben Thurley

Do this:
1. Go to the folder where eclipse is installed (the one that has the eclipse.exe program in)
2. Open the text file eclipse.ini with notepad or something similar
3. Add the following lines to specify the JVM location using the -vm argument

执行此操作:
1. 转到安装 eclipse 的文件夹(其中包含 eclipse.exe 程序的文件夹)
2. 使用记事本或类似工具打开文本文件 eclipse.ini
3. 添加以下几行以指定 JVM 位置使用 -vm 参数

-vm 
c:/jre/bin/javaw.exe  

Now start eclipse in the usual way.

现在以通常的方式启动 eclipse。

Make sure to position the -vm argument before -vmargs, since the latter is passed to the VM on startup it will be too late to set the VM after this.

确保将 -vm 参数放在 -vmargs 之前,因为后者在启动时传递给 VM,在此之后设置 VM 为时已晚。

More info is available on the Eclipse wiki

Eclipse wiki上提供了更多信息

You could also have changed the system path as per one of the other answers but this would change the JVM being used for the whole system. If you use the eclipse.ini settings it allows everything else to use the latest JVM.

您也可以根据其他答案之一更改系统路径,但这会更改用于整个系统的 JVM。如果您使用 eclipse.ini 设置,它允许其他所有内容使用最新的 JVM。

回答by Johny Jaz

Since none of the answers worked for me this is my solution:

由于没有一个答案对我有用,这是我的解决方案:

I downloaded java 6 and i installed it. Then in the program files, inside the folder of java , i copied the folder jre6. I pasted it inside the eclipse folder and renamed it jre.

我下载了 java 6 并安装了它。然后在程序文件中,在 java 文件夹内,我复制了文件夹 jre6。我将它粘贴到 eclipse 文件夹中并将其重命名为jre

Thats it! When inside the eclipse installation folder your have a folder named jre, then the java in there is the java that eclipse will run with.

就是这样!当在 eclipse 安装文件夹中有一个名为jre的文件夹时,其中的 java 就是 eclipse 将运行的 java。

Thank you all for your answers!

谢谢大家的答案!

回答by Van Dan NGUYEN

  • Open eclipse config file eclipse.iniin your Eclipse folder.
  • Add -vm yourPath\Java\jre6\bin\javaw.exelike:

    -startup
    plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
    --launcher.library
    plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120522-1813
    -product
    org.eclipse.epp.package.java.product
    --launcher.defaultAction
    openFile
    --launcher.XXMaxPermSize
    256M
    -vm 
    C:\Java\jre6\bin\javaw.exe
    ...
    
  • eclipse.ini在 Eclipse 文件夹中打开 Eclipse 配置文件。
  • 添加-vm yourPath\Java\jre6\bin\javaw.exe像:

    -startup
    plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
    --launcher.library
    plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120522-1813
    -product
    org.eclipse.epp.package.java.product
    --launcher.defaultAction
    openFile
    --launcher.XXMaxPermSize
    256M
    -vm 
    C:\Java\jre6\bin\javaw.exe
    ...
    

If the path contains spaces there is no need to escape them, see the Eclipse Wikifor more specs. The -vmoption and the path must be on separate lines. The -vmoption must come before the -vmargsoption. On Linux, the path would typically be /bin/javainstead of the Windows path shown above. You must use the Java and Eclipse versions must match (i.e. 32-bit Eclipse runs on 32-bit Java and 64-bit Eclipse runs on 64-bit Java).

如果路径包含空格,则无需对它们进行转义,请参阅Eclipse Wiki以获取更多规范。该-vm选项和路径必须在单独的行。该-vm选项必须出现在面前-vmargs的选择。在 Linux 上,路径通常会/bin/java代替上面显示的 Windows 路径。您必须使用的 Java 和 Eclipse 版本必须匹配(即 32 位 Eclipse 运行在 32 位 Java 上,而 64 位 Eclipse 运行在 64 位 Java 上)。

回答by BugaBuga

Note that option -vm C:\Java\jre6\bin\javaw.exeshould be right before -vmargs. Otherwise you'll get 'Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit'

请注意,选项-vm C:\Java\jre6\bin\javaw.exe应该在-vmargs. 否则,您将收到“错误:无法创建 Java 虚拟机”。错误:发生了致命异常。程序将会退出'

回答by staiiir

Many hints given already. Anyway I will just provide the recommended way of doing itwhich might help for future reviews of that question:

已经给出了很多提示。无论如何,我只会提供推荐的方法,这可能有助于将来对该问题的评论:

  1. Use the eclispe.ini file (folder where the eclipse binary resides)
  2. Add the -vm option with the path of the jre to startup with

    i.e Windows
    -vm
    C:\Java\jdk1.6.0_45\jre\bin\javaw.exe
    i.e Linux
    -vm
    /opt/sun-jdk-1.6.0.02/bin/java

  3. The -vm option must occur after the other Eclipse-specific options (such as -product, --launcher.*, etc), but before the -vmargs option, since everything after -vmargs is passed directly to the JVM.
  4. The -vm option and its value (the path) must be on separate lines.
  5. The value must be the full absolute or relative path to the Java executable, not just to the Java home directory.
  1. 使用 eclispe.ini 文件(eclipse 二进制文件所在的文件夹)
  2. 添加 -vm 选项和 jre 的路径以启动

    即 Windows
    -vm
    C:\Java\jdk1.6.0_45\jre\bin\javaw.exe
    即 Linux
    -vm
    /opt/sun-jdk-1.6.0.02/bin/java

  3. -vm 选项必须出现在其他特定于 Eclipse 的选项(例如 -product、--launcher.* 等)之后,但在 -vmargs 选项之前,因为 -vmargs 之后的所有内容都直接传递给 JVM。
  4. -vm 选项及其值(路径)必须在不同的行中。
  5. 该值必须是 Java 可执行文件的完整绝对或相对路径,而不仅仅是 Java 主目录。

see: the eclipse.ini authoring guidelines from eclipse wiki

请参阅:来自 eclipse wiki 的 eclipse.ini 创作指南

回答by Alok Rajput

I too faced same issue while running eclipse with different version then default on the system.

在使用不同版本然后在系统上默认运行 eclipse 时,我也遇到了同样的问题。

I created a symlink of required jre directory under eclipse directory and then it was all working.

我在 eclipse 目录下创建了所需 jre 目录的符号链接,然后一切正常。

For windows user: symlink is similar to creating shortcut

对于 Windows 用户:符号链接类似于创建快捷方式

Hope it helps you too.

希望对你也有帮助。

回答by Sabeesh

These two options worked for me on Windows:

这两个选项在 Windows 上对我有用:

  1. Edit eclipse.ini

    -vm
    
    C:/Java/jdk1.7.0_71/jre/bin
    
    -vmargs
    ...
    
  2. Copy jre folder to eclipse folder.

  1. 编辑 eclipse.ini

    -vm
    
    C:/Java/jdk1.7.0_71/jre/bin
    
    -vmargs
    ...
    
  2. 将 jre 文件夹复制到 eclipse 文件夹。

So after the copy I have C:\eclipse\jre folder which is a copy of C:\Java\jdk1.7.0_71\jre

所以复制后我有 C:\eclipse\jre 文件夹,它是 C:\Java\jdk1.7.0_71\jre 的副本

回答by vani saladhagu

I modified eclipse.ini file as follows (added my local JDK path) and it fixed eclipse loading issue.

我按如下方式修改了 eclipse.ini 文件(添加了我的本地 JDK 路径)并修复了 eclipse 加载问题。

-vm
C:\Program Files\Java\jdk1.8.0_251\bin