简体   繁体   English

Eclipse:对Java 1.7的沮丧(未绑定的库)

[英]Eclipse: Frustration with Java 1.7 (unbound library)

I'm having trouble with a brand new project in a brand new installation of Eclipse. 我在全新的Eclipse安装中遇到了一个全新的项目。 Repro steps: 复制步骤:

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

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

  3. Launch Eclipse; 启动Eclipse; choose a workspace 选择一个工作区

  4. File > New > Java Project 文件 > 新建 > Java项目

  5. Project name: Hello World . 项目名称: Hello World JRE: "Use an execution environment JRE: JavaSE-1.7" JRE:“使用执行环境JRE:JavaSE-1.7”

  6. Hit Next , go to the Libraries tab. 点击“ 下一步” ,转到“库”选项卡。 The only entry is JRE System Library [JavaSE-1.7] (unbound) . 唯一的条目是JRE系统库[JavaSE-1.7](未绑定) What does "unbound" mean? “未绑定”是什么意思? How do I fix it? 我如何解决它?

  7. Hit Finish . 点击完成

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. 更新:也许我的机器上实际上没有Java 7 JDK。 How can I be sure? 我如何确定?

Update 2: Looks like Java 7 is in fact not out yet. 更新2:看起来Java 7实际上尚未发布。 Sweet. 甜。

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. 1)找出驱动器上Java的安装位置,打开cmd提示符,转到该位置并运行“。\\ java -version”以找出确切的版本。 Or, quite simply, check the add/remove module in the control panel. 或者,非常简单地,检查控制面板中的添加/删除模块。

2) After you actually install jdk 7, you need to tell Eclipse about it. 2)实际安装jdk 7之后,您需要将其告知Eclipse。 Window -> Preferences -> Java -> Installed JREs. 窗口->首选项-> Java->已安装的JRE。

To set JDK you can watch this video : how to set JDK . 要设置JDK,您可以观看以下视频: 如何设置JDK Then when you'll have 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)" 单击“ JRE系统库[JavaSE-1.7](未绑定)”
  4. Edit it 编辑它
  5. Choose "Alternate JRE" 选择“备用JRE”
  6. Click on "Installed JREs.." button 单击“已安装的JRE。”按钮
  7. Press Add 按添加
  8. Choose to add "Standard VM" 选择添加“标准VM”
  9. Choose JRE Home directory - usually it is locates in "C:\\Program Files\\Java\\jre7" directory 选择JRE主目录-通常位于“ C:\\ Program Files \\ Java \\ jre7”目录中
  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. 重新检查新出现的“ Jre7”:验证是否在编辑“ JRE系统库[JavaSE-1.7]”时为jre7选择了“备用JRE”。

1)Go to configure build path . 1)转到配置构建路径。 2)Remove unbound JRE library . 2)删除未绑定的JRE库。 3)Add library --> JRE System library . 3)添加库-> JRE系统库。

Then project compile and done .. 然后项目编译并完成..

Most of the time after the installation of Eclipse eclipse.ini is changed. 在安装Eclipse eclipse.ini之后,大部分时间都会更改。 If you change the jdk in eclipse.ini then eclipse will use this jdk by default. 如果您在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. 假设您安装了新版本的Eclipse,但您忘记更改与jdk相关的eclipse.ini。 Then Eclipse finds a jdk for you. 然后Eclipse为您找到一个jdk。 Let's say it is java 1.6 that was automatically discovered (you did nothing). 假设是Java 1.6被自动发现(您什么也没做)。

If you use maven (M2E) and you reference a 1.7 jdk then you will see the frustrating message. 如果使用maven(M2E)并引用1.7 jdk,则将看到令人沮丧的消息。 But normally it is not displayed because you configure the correct jdk in eclipse.ini. 但是通常不会显示它,因为您在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. 在屏幕截图中,您可以看到Eclipse已配置并看到1.7。 In this case, you should make reference into the pom to a jre that is compatible with 1.7! 在这种情况下,您应该在pom中引用与1.7兼容的jre! If not -> frustrating message! 如果没有->令人沮丧的消息!

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

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. 您可以试玩这些功能,尽管它并不稳定,所以您不应该针对这些功能发布软件。

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 从显示的列表中选择“ JRE系统库”
  • Click on "Next" followed by "Finish" button 单击“下一步”,然后单击“完成”按钮

This will point your system's proper & valid JRE path, which did thing for me. 这将指出您系统的正确且有效的JRE路径,这对我来说是有用的。 Cheers :) 干杯:)

Updated eclipse.ini file with key value property -Dosgi.requiredJavaVersion=1.7 (or) 1.8 whichever applicable. 使用键值属性-Dosgi.requiredJavaVersion = 1.7(或)1.8(以适用者为准)更新了eclipse.ini文件。 - it works for me. - 这个对我有用。

Updated eclipse.ini file 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.8 as my project library 另外,选择JRE 1.8作为我的项目库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM