79

How can I download the source code of Java on my local machine, so I can reference it in an IDE?

115

Example for Java 8:

sudo apt-get install openjdk-8-source

apt-get puts it under the relevant JDK location as src.zip: /usr/lib/jvm/java-8-openjdk-amd64/src.zip

Intellij IDEA recognized it automatically and started showing me the source code.

2
  • Awesome, thank you
    – ata
    Apr 13 '20 at 13:00
  • You are a champ you know that.! Dec 26 '20 at 14:59
34

In case of java 11 (on Ubuntu 18.04) I did:

First I install jdk 11:

sudo apt install openjdk-11-jdk

I install the sources like this:

sudo apt-get install openjdk-11-source

And I found them in /usr/lib/jvm/openjdk-11/lib/src.zip

I use Eclipse so I go inside Eclipse's menu Window -> Preferences -> Installed JREs and inside select java-11-openjdk-amd64 -> edit -> select the jar (jrt-fs.jar) -> Source Attachment -> External location -> /usr/lib/jvm/openjdk-11/lib/src.zip

Now I happily read the java documentation! :)

Best of luck to all!

2
  • Where is the jrt-fs.jar? Is it inside the .zip?
    – birgersp
    Mar 4 '20 at 18:51
  • No jrt-fs.jar should be in the lib directory of your JDK. For example /usr/lib/jvm/java-11-openjdk-amd64/lib/jrt-fs.jar Please check if you have it after you install sudo apt install openjdk-11-jdk In Eclipse menu you can see it after you press edit button on the selected JDK and you can see it in JRE system libraries section.
    – Level_Up
    Mar 5 '20 at 9:00
0

In case of java 13 simply run sudo apt-get install openjdk-13-source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.