简体   繁体   中英

How Do You Install the source for the java libraries in Eclipse?

如何在Eclipse中安装java库的源代码?

This happens automatically if you set up a JDK rather than a JRE.

Normally, when you start eclipse, it sets up the JRE that was used to start eclipse. You'll usually want to override this with a JDK so you get the source. To do this:

  1. First, make sure you have a JDK installed (and not just a JRE)
  2. Start eclipse
  3. Go to Window->Preferences->Java->Installed JREs
  4. Press Add...
  5. Choose "Standard VM" and press "Next..."
  6. Press "Directory...", select the JDK installation directory and press "Ok"
  7. Press "Finish"
  8. Make sure you check the box next to the new JDK
  9. Press "Ok" to finish up

This will set up the source properly for you.

You can do it in the project preferences, but I find quite faster just to ctr+click over a object or class defined in the standard library and then "attach source" in the page that will gently inform you that there are no sources attached.

You then can point to the "src.zip" in your JDK distribution.

The way that I do it:

Prerequisite: you have the source downloaded. It comes with the JDK. (src.zip)

  1. Open up a Java file
  2. Ctrl + Click on a class name.
  3. Click on the button that says 'Attach Source'
  4. Locate the src.zip file. (Usually in the JDK install location)
  5. Now you have the source installed!

WHat do you mean with java source? The java.lang package? Because there shouldn't be a need to "install" them. Creating a new Java Project ( any kind of Java Project) should be enough. Could you describe your problem in more detail?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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