Eclipse:对 Java 1.7 的挫折(未绑定库)

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

Eclipse: Frustration with Java 1.7 (unbound library)

javaeclipseide

提问by Nick Heiner

I'm having trouble with a brand new project in a brand new installation of Eclipse. Repro steps:

我在全新安装的 Eclipse 中遇到了一个全新项目的问题。复现步骤:

  1. Download this version of Eclipse: http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/heliosr

  2. Unzip to c:\program files\eclipse java

  3. Launch Eclipse; choose a workspace

  4. File> New> Java Project

  5. Project name: Hello World. JRE: "Use an execution environment JRE: JavaSE-1.7"

  6. Hit Next, go to the Libraries tab. The only entry is JRE System Library [JavaSE-1.7] (unbound). What does "unbound" mean? How do I fix it?

  7. Hit Finish.

  1. 下载此版本的 Eclipse:http: //www.eclipse.org/downloads/packages/eclipse-ide-java-developers/heliosr

  2. 解压到c:\program files\eclipse java

  3. 启动日食;选择工作区

  4. 文件>新建> Java 项目

  5. 项目名称:你好世界。JRE:“使用执行环境 JRE:JavaSE-1.7”

  6. 点击Next,转到 Libraries 选项卡。唯一的条目是JRE System Library [JavaSE-1.7] (unbound)。“未绑定”是什么意思?我如何解决它?

  7. 点击完成

Expected: Brand new project works fine.

预期:全新项目运行良好。

Actual: There are two errors:

实际:有两个错误:

The project cannot be built until build path errors are resolved HelloWord  Unknown Java Problem
Unbound classpath container: 'JRE System Library [JavaSE-1.7]' in project 'HelloWord' HelloWord  Build path Build Path Problem

What am I doing wrong here?

我在这里做错了什么?

Update:Perhaps I don't actually have the Java 7 JDK on my machine. How can I be sure?

更新:也许我的机器上实际上没有 Java 7 JDK。我怎么确定?

Update 2:Looks like Java 7 is in fact not out yet. Sweet.

更新 2:看起来 Java 7 实际上还没有发布。甜的。

回答by Sinjo

Have you actually downloaded and installed one of the milestone builds from https://jdk7.dev.java.net/?

您是否真的从https://jdk7.dev.java.net/下载并安装了里程碑版本之一?

You can have a play with the features, though it's not stable so you shouldn't be releasing software against them.

您可以尝试使用这些功能,尽管它不稳定,因此您不应该发布针对它们的软件。

回答by Yoni

1) Find out where java is installed on your drive, open a cmd prompt, go to that location and run ".\java -version" to find out the exact version. Or, quite simply, check the add/remove module in the control panel.

1) 找出驱动器上安装 java 的位置,打开 cmd 提示符,转到该位置并运行“.\java -version”以找出确切版本。或者,很简单,检查控制面板中的添加/删除模块。

2) After you actually install jdk 7, you need to tell Eclipse about it. Window -> Preferences -> Java -> Installed JREs.

2)实际安装jdk 7后,需要告诉Eclipse。窗口 -> 首选项 -> Java -> 已安装的 JRE。

回答by Rudy Vissers

Most of the time after the installation of Eclipse eclipse.ini is changed. If you change the jdk in eclipse.ini then eclipse will use this jdk by default.

Eclipse 安装后大部分时间eclipse.ini 是有变化的。如果您在 eclipse.ini 中更改 jdk,则 eclipse 将默认使用此 jdk。

Let's say you install a new version of Eclipse and you have forgotten to change the eclipse.ini related to the jdk. Then Eclipse finds a jdk for you. Let's say it is java 1.6 that was automatically discovered (you did nothing).

假设您安装了新版本的 Eclipse,而您忘记更改与 jdk 相关的 eclipse.ini。然后 Eclipse 会为您找到一个 jdk。假设它是自动发现的 java 1.6(您什么也没做)。

If you use maven (M2E) and you reference a 1.7 jdk then you will see the frustrating message. But normally it is not displayed because you configure the correct jdk in eclipse.ini.

如果您使用 maven (M2E) 并引用 1.7 jdk,那么您将看到令人沮丧的消息。但是一般情况下是不会显示的,因为你在eclipse.ini中配置了正确的jdk。

That was my case. I made reference into the pom to a jdk that was not configured into Eclipse.

这就是我的情况。我在 pom 中引用了未配置到 Eclipse 中的 jdk。

In the screenshot you can see that 1.7 is configured and seen by Eclipse. In this case, you should make reference into the pom to a jre that is compatible with 1.7! If not -> frustrating message!

在屏幕截图中,您可以看到 Eclipse 已配置和查看 1.7。在这种情况下,您应该在 pom 中引用与 1.7 兼容的 jre!如果没有 -> 令人沮丧的消息!

jdk 1.7 configured in eclipse.ini and retrieved in installed jre

jdk 1.7 在 eclipse.ini 中配置并在已安装的 jre 中检索

回答by Mahesh

1)Go to configure build path . 2)Remove unbound JRE library . 3)Add library --> JRE System library .

1)去配置构建路径。2) 删除未绑定的 JRE 库。3)添加库--> JRE系统库。

Then project compile and done ..

然后项目编译并完成..

回答by Anahit Serobyan

To set JDK you can watch this video : how to set JDK. Then when you'll have JDK:

要设置 JDK,您可以观看此视频:如何设置 JDK。然后,当您拥有 JDK 时:

  1. Right click on build path and select "Build Path"
  2. Choose "Configure Build Path"
  3. Click on "JRE System Library [JavaSE-1.7] (unbound)"
  4. Edit it
  5. Choose "Alternate JRE"
  6. Click on "Installed JREs.." button
  7. Press Add
  8. Choose to add "Standard VM"
  9. Choose JRE Home directory - usually it is locates in "C:\Program Files\Java\jre7" directory
  10. Press "Finish"
  11. Re-check newly appeared "Jre7": Verify that now when you edit "JRE System Library [JavaSE-1.7]" "Alternate JRE" is chosen for jre7.
  1. 右键单击构建路径并选择“构建路径”
  2. 选择“配置构建路径”
  3. 点击“JRE系统库[JavaSE-1.7](未绑定)”
  4. 编辑它
  5. 选择“备用 JRE”
  6. 单击“已安装的 JRE..”按钮
  7. 按添加
  8. 选择添加“标准虚拟机”
  9. 选择 JRE Home 目录 - 通常它位于“C:\Program Files\Java\jre7”目录中
  10. 按“完成”
  11. 重新检查新出现的“Jre7”:验证现在编辑“JRE 系统库 [JavaSE-1.7]”时是否为 jre7 选择了“备用 JRE”。

回答by NarendraC

Cause : This is common scenario when we import new project with different lib and JAR path.

原因:当我们使用不同的 lib 和 JAR 路径导入新项目时,这是常见的情况。

I faced this issue and got resolved using exact following steps:

我遇到了这个问题,并使用以下步骤得到了解决:

  • Project> Properties
  • Build Path> Configure Build Path
  • Select "Libraries"tab
  • Click "Add Library"
  • Select "JRE System Library"from displayed list
  • Click on "Next"followed by "Finish"button
  • 项目>属性
  • 构建路径>配置构建路径
  • 选择“库”选项卡
  • 点击“添加库”
  • 从显示的列表中选择“JRE 系统库”
  • 单击“下一步”,然后单击“完成”按钮

This will point your system's proper & valid JRE path, which did thing for me. Cheers :)

这将指向您的系统正确且有效的 JRE 路径,这对我有用。 干杯:)

回答by Mahendran

Updated eclipse.ini file with key value property -Dosgi.requiredJavaVersion=1.7 (or) 1.8 whichever applicable. - it works for me.

使用键值属性 -Dosgi.requiredJavaVersion=1.7(或)1.8 更新 eclipse.ini 文件,以适用者为准。- 这个对我有用。

回答by Masoud Oveis Gharan

Updated eclipse.inifile with key-value property

eclipse.ini具有键值属性的更新文件

-Dosgi.requiredJavaVersion=1.5 

to

-Dosgi.requiredJavaVersion=1.8

because, that is my JAVA version.

因为,那是我的JAVA版本。

Also, selected JRE 1.8as my project library

另外,选为JRE 1.8我的项目库