10. Using jars (libraries)
The following describes how to add Java libraries to your project. Java libraries are distributed via "jar" files. It assumes that you have a jar file available; if not feel free to skip this step.
Create a new Java project
From the menu select → → → . Select your jar and select the folder
Right click on your project and select Properties. Under → select the button "Add JARs".
The following example shows how the result would look like, if the junit-4.4.jar had been added to the project.
Afterwards you can use the classes contained in the
Create a new Java project
de.vogella.eclipse.ide.jars
. Then, create a new folder called lib
, by right clicking on your project and selecting → .From the menu select → → → . Select your jar and select the folder
lib
as target. Alternatively, just copy and paste your jar
file into the "lib" folder.Right click on your project and select Properties. Under → select the button "Add JARs".
The following example shows how the result would look like, if the junit-4.4.jar had been added to the project.
Afterwards you can use the classes contained in the
jar
file in your Java source code.As said earlier you can open any class via positioning the cursor on the class in an editor and pressing F3. Alternatively, you can press CTRL+Shift+T. This will show a dialog in which you can enter the class name to open it.
If the source code is not available when you attempt to open a class, the editor will show the decompiled byte-code of that class.
This happens if you open a class from a
To browse the source of a type contained in a library (i.e. .jar file), you can attach a source archive or source folder to that library. Afterwards the editor will show the source instead of the byte-code.
In addition setting the source attachment allows debugging this source code.
The Source Attachment dialog can be reached in the Java Build Path page of a project. To open this page, → → . On the "Libraries" tab, expand the library's node, select the "Source attachment" attribute and press Edit.
In the Location path field, enter the path of an archive or a folder containing the source.
The following shows this for the standard Java library. If you have the Java Development Kit (JDK) installed, you should find the source in the JDK installation folder. The file is typically called "src.zip".
If the source code is not available when you attempt to open a class, the editor will show the decompiled byte-code of that class.
This happens if you open a class from a
jar
file and the source for this jar is not available.To browse the source of a type contained in a library (i.e. .jar file), you can attach a source archive or source folder to that library. Afterwards the editor will show the source instead of the byte-code.
In addition setting the source attachment allows debugging this source code.
The Source Attachment dialog can be reached in the Java Build Path page of a project. To open this page, → → . On the "Libraries" tab, expand the library's node, select the "Source attachment" attribute and press Edit.
In the Location path field, enter the path of an archive or a folder containing the source.
The following shows this for the standard Java library. If you have the Java Development Kit (JDK) installed, you should find the source in the JDK installation folder. The file is typically called "src.zip".
It is also possible to add Javadoc to a library which you use.
Download the Javadoc of the jar and put it somewhere in your filesystem.
Open the Java Build Path page of a project via → → . On the "Libraries" tab expand the library's node, select the "Javadoc location" attribute and press Edit.
Enter the location to the file which contains the Javadoc.
Download the Javadoc of the jar and put it somewhere in your filesystem.
Open the Java Build Path page of a project via → → . On the "Libraries" tab expand the library's node, select the "Javadoc location" attribute and press Edit.
Enter the location to the file which contains the Javadoc.
Source Link : http://www.vogella.de/articles/Eclipse/article.html