Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I view JRE's source code in Eclipse on linux (debian)

Tags:

java

eclipse

I have a debian machine. I am using eclipse. Normally on eclipse, to view the source of code of an object, etc, you simply click F3 on the object. But for some reason, when it's core java classes, I get

 "Source not found" and an option to attach the source.

Where exactly is the JRE source on debian? When I do a aptitude search "?provides(java-runtime)", the result contains multiple answers with the substring jre in it and also no path.

Can someone tell me exactly where to get the source so I can attach it. Also, I would like to make it available to all projects, not just per project.

like image 906
user1467855 Avatar asked Jul 31 '12 23:07

user1467855


People also ask

How can I view source code in Eclipse?

Go to Windows->Preferences->Java->Installed JREs. Select Browse and navigate to the C:\Program Files\Java\jdk1. 6.0_21 directory. Eclipse will automatically find the source and associate it with the JDK classes.

How can I see predefined classes in Eclipse?

Clicking anywhere on the class name that we want to open and pressing F3. Clicking anywhere on the class name and going to the menu under Navigate > Open Declaration.


Video Answer


3 Answers

The JRE is purely the runtime environment needed to run Java programs. For the development of Java programs, you need the JDK (Java Development Kit).

The JDK itself is split up into several packages, including the JRE, documentation, demos, and the source files.

Assuming that you're using Open JDK 6, sudo apt install openjdk-6-source would install and link the source code that you're looking for.

like image 92
Jamie Avatar answered Oct 07 '22 09:10

Jamie


This worked for me in Ubuntu 14.10, Eclipse Kepler using openjdk-8

Window > Preferences > Java > Installed JREs > Click on your java-8-openjdk > Edit

For /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:

set Source attachment to:

/usr/lib/jvm/java-8-openjdk-amd64/src.zip

set Javadoc location to:

file:/usr/share/doc/openjdk-8-doc/api/

NOTE: If you don't already have the openjdk-8 java doc, install:

sudo apt-get install openjdk-8-doc

and for the source:

sudo apt-get install openjdk-8-source
like image 35
Casey Murray Avatar answered Oct 07 '22 11:10

Casey Murray


sudo apt-get intall java-6-openjdk was successful for me on Ubuntu 11.04 LTS. Additionally,if you are using the Eclipse IDE, I went through Window/Preferences/InstalledJREs/java-6-openjdk-amd64/Edit(find rt.jar ) and then Add External File src.zip as shown in the screen shot.enter image description here

like image 36
user28095 Avatar answered Oct 07 '22 10:10

user28095