When you add a JAR file or folder of compiled classes to a project's classpath,
it is often useful to add the source files for those classes so that you
can view their contents when working with them. Attaching source code to a
JAR file or compiled classes folder lets the IDE know where to find the source
code for those classes. You can then step into the source files when debugging
and open the source files with the Go To Source command.
In order for code completion to work properly in the IDE, you must either
attach a complete set of source files as a folder or add the available
source files as a Zip archive.
To attach source code to a JAR file or compiled classes folder:
Choose Tools > Libraries from the main menu.
In the left pane of the Library Manager, select the project library within
which the JAR file you want to add the source code to is located.
Only libraries already registered with the IDE are listed in the Library Manager's
Class Libraries list.
If the JAR file or classes folder for which you want to add the source
code has not already been added to a registered library, create a new empty
library using the New Library button. Next, in the Classpath tab click Add JAR/Folder and specify the
location of the JAR file containing the compiled class files.
A class library can contain multiple JAR files as well as their Javadoc documentation and
source code.
In the Sources tab, click Add JAR/Folder to add the folder or archive file
containing the source code.
Click OK to exit the Library Manager.
The IDE adds the selected JAR files and source code to the specified library
and automatically registers the source code in every project
that has that JAR file on its classpath.
When you create a Java class library for a
single JAR file, you can simply add the JAR file to the project's classpath
to make the associated Javadoc and source code available. If your
Java library contains multiple JAR files, however, you must add the library
itself to the classpath. Adding the library to the classpath also makes
it easier to share the project with other developers.
You can also associate the sources with a JAR file using the project's Project
Properties window. However, doing so creates the association only for that project.
Open the Project Properties dialog box by right-clicking the project node and
choosing Properties. Select the Libraries node in the Categories pane. Then
select the JAR with which you want to associate the sources and click Edit. You can
then specify the sources to be associated.
To attach source code for a Java platform:
Choose Tools > Java Platforms from the main menu.
Select the platform in the left pane of the dialog box.
In the Sources tab, add the folders or archive files containing the source code.
For
, you set the target JDK in your Ant script and specify the source
level in the Project Properties dialog box. When you step into
JDK classes, the IDE searches the platforms registered in the Java Platform
Manager for a Java platform with a matching source level. If no matching
Java platform is found, the IDE opens the source code for the IDE's default
platform.