简体   繁体   English

Eclipse Java Project:工作代码中出现“找不到源”投诉

[英]Eclipse Java Project: “Source not found” complaint in working code

Everything in an Eclipse Java project is working fine but when I override toString() and equals() a green arrow I do not recognize appears in the margin of the text editor beside the start of the overriding method declaration. Eclipse Java项目中的所有程序都可以正常工作,但是当我覆盖toString()和equals()时,一个我无法识别的绿色箭头出现在文本编辑器的覆盖方法声明开始处的空白处。 When I click on it I get a new tab in the editor titled "Class File Editor" and the message under an apparent "Source not found" complaint reads: 当我单击它时,我在编辑器中获得一个名为“类文件编辑器”的新选项卡,明显的“未找到源”投诉下的消息显示为:

The JAR file C:/Program Files/Java/jre7/lib/rt.jar has no source attachment. JAR文件C:/ Program Files / Java / jre7 / lib / rt.jar没有源附件。

and there is an option to add the apparently missing source. 并且可以选择添加显然缺少的源。 However, the code works just fine as is. 但是,该代码可以正常工作。 For example, the output of this: 例如,此输出:

class TestClass
{
   @Override
   public String toString() // <--- green arrow appears in the margin on this line
   {
      return "Class TestClass";
   }

   public static void main(String[] args)
   {
      TestClass tc = new TestClass();
      System.out.println(tc.toString());
   }
}

Is the expected: 是预期的:

Class TestClass

despite the apparent complaint. 尽管有明显的抱怨。

Various other posters seem to have encounted a similar complaint with actual consequences while debugging but that is not the case here. 其他各种张贴者似乎在调试时也遇到了类似的抱怨,并带有实际后果,但事实并非如此。 Can someone explain what is happening and what, if anything, I should do about it? 有人可以解释正在发生的事情,如果有的话,我应该怎么做?

It's a message where the classpath for the app you're running doesn't have the sources for the rt.jar being used (more directly, Eclipse couldn't find a matching qualified source file for the class being shown). 这是一条消息,其中您正在运行的应用程序的类路径没有使用rt.jar的源(更直接地,Eclipse找不到正在显示的类的匹配合格源文件)。 That classpath is based on the JRE System Library in the project's Java Build Path . 该类路径基于项目的Java Build PathJRE System Library

It's not about which one is running Eclipse. 这与运行Eclipse的对象无关 It's entirely about which one the project points to. 这完全取决于项目所指向的对象。 If you want sources easily found for what's in the standard class library, set the JRE for the project to point to a JDK instead. 如果要在标准类库中轻松找到源代码,请将项目的JRE设置为指向JDK

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

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