0

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. 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.

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?

Schemer
  • 1,635
  • 4
  • 19
  • 39
  • not sure about this, but this may be related to eclipse is being run by a jre instead of a jdk, or in the "installed jre" list, you should replace a jre with a jdk (sorry, I am really no sure) – Leo Sep 10 '14 at 23:44
  • @Leo: Thanks. Eclipse was running under a jre. I followed the instructions here [link]http://www.gamefromscratch.com/post/2011/11/15/Telling-Eclipse-to-use-the-JDK-instead-of-JRE.aspx and here [link]http://matsim.org/docs/devguide/eclipse/jdk but under `Help-->About Eclipse-->Installation Details` the argument to `-vm` is still the original `C:\Windows\system32\javaw.exe` so I do not know if either method had any effect and the issue remains. – Schemer Sep 11 '14 at 00:42
  • To check if my installation was wonky, I downloaded another version of Eclipse and I get the same behaviour -- including the same argument to `-vm` in `Installation Details`. It must be a configuration issue. – Schemer Sep 11 '14 at 01:45

1 Answers1

0

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). That classpath is based on the JRE System Library in the project's Java Build Path.

It's not about which one is running 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.

nitind
  • 19,089
  • 4
  • 34
  • 43
  • The jdk is on the build path for the project. If the problem is because the project cannot find the standard class library, why would the superclass methods be available in the first place? – Schemer Sep 11 '14 at 13:51
  • It's complaining about not finding the sources for `C:/Program Files/Java/jre7/lib/rt.jar` right? Then it's at least running with the JRE rather than the JDK--maybe something to update in an existing launch configuration? – nitind Sep 11 '14 at 15:32
  • Well, for whatever reason, editing the eclipse.ini files yet again finally had the desired effect. Now the green arrow opens a new tab displaying the source code. This poster on SO [link]http://stackoverflow.com/questions/1917760/howto-start-eclipse-in-jdk also seems to have had trouble with editing the .ini files. – Schemer Sep 11 '14 at 19:49
  • Actually, I have no idea what happened. Windows search was returning eclipse.ini files from a backup folder and _not_ the current installations. So editing those files could not have changed anything. Yet the behaviour has suddenly changed. I had already updated the build paths to include the jdk and restarted both installations so that effect should have already happened. Gonna chalk this one up to a ghost in the machine. – Schemer Sep 11 '14 at 20:17