Search code examples
javaeclipseinternals

Source not found for internal java classes in eclipse


I use eclipse and lots of times I need to open a source file of an internal class in java. I do this by pressing ctrl + click on that object. For example I want to see the codes of the Scanner class, and when I try to open it by ctrl + click on a Scanner object, it shows that, "source is not found". The error is this:

The JAR file in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar has no source attachment.

You can attach the source by clicking Attach Source below:

And there is an Attach Source button under it. I searched a lot but all people had the same problem with the projects on their filesystem, not the internal classes. What should I do? Is there a way to change that /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar file?


Solution

  • Just do

    $ sudo apt install openjdk-8-source
    $ sudo updatedb
    $ mlocate src.zip
    

    Copy the last command's location. It usually is /usr/lib/jvm/openjdk-8/src.zip.

    Then, click Attach Source..., and click on External location. Then paste that command's output in the text field. (You can open the file by clicking on External File... and finding that src.zip file in your filesystem.)