When your Java project needs a JAR (Java Archive) library to function, you need to configure it to include the library in its build path. Thanks to Eclipse, this process is simple and easy to remember. This article covers Java Eclipse - Ganymede 3.4.0.
Step
Method 1 of 2: Adding an Internal JAR
Step 1. Copy the JAR that will be used for your project
Here's how to do it:
-
Create a folder called lib in your project folder. “Lib” means library and holds all the JARs that will be used for this project.
Add JARs to Project Build Paths in Eclipse (Java) Step 1Bullet1 -
Copy the required JAR to the lib.
Add JARs to Project Build Paths in Eclipse (Java) Step 1Bullet2 -
Reload your project by right-clicking the project name and selecting Refresh. Folders lib will now be viewable in eclipse with all JARs in it.
Add JARs to Project Build Paths in Eclipse (Java) Step 1Bullet3
Step 2. Complete one of the methods below to configure your build path
Method 1

Step 1. Develop lib in eclipse and select all required JARs

Step 2. Right click the JAR and go to Build Path

Step 3. Select Add to Build Path
JAR will disappear from lib and reappear in Referenced Libraries.
Method 2

Step 1. Right click the project name and go to Build Path

Step 2. Select Configure Build Path
.. and the project properties window will appear showing your build path configuration.

Step 3. Select the Libraries label

Step 4. Click Add JARs
..

Step 5. Locate and select the desired JAR and click OK
The JAR will now appear in the list in the build path.

Step 6. Click OK to close the properties window
JAR will now be in Referenced Libraries instead lib.
Method 2 of 2: Adding External JAR
Note: It's better that you reference the existing JAR in your project or another project. This allows you to check in all dependencies to your version control system (you must use version control).
Use one of the following methods.
Method 1
This is the recommended method as it allows different developers of similar projects to find their external JARs in different places.

Step 1. Right click the project name and go to Build Path

Step 2. Select Configure Build Path
.. and the project properties window will appear showing your build path configuration.

Step 3. Click Add Variable
..

Step 4. Click Configure Variables
..

Step 5. Click New
..

Step 6. Type a name for the new variable
For example, if all of these JARs are for Tomcat, we recommend typing TOMCAT_JAR.

Step 7. Go to the directory that holds the JAR for the path (you can also select a specific JAR file for the variable)

Step 8. Click Ok to define the variables

Step 9. Click Ok to close the preferences dialog

Step 10. Select a variable from the list

Step 11. Click Extend
..

Step 12. Select the JAR you want to add to the classpath

Step 13. Click Ok to close the dialog

Step 14. Click Ok to close the new classpath variables dialog

Step 15. Click Ok to close the build path setup dialog
-
If you share this project with other people, they must also define the variables. They can determine it through
''''Window->Preferences->Java->Build Path->Classpath Variables''''
Method 2
Note that if you use this method, the external JAR must be in the same location on the hard drive as anyone using this project. This makes sharing projects more difficult.

Step 1. Right click the project name and go to Build Path

Step 2. Select Add External Archives
..

Step 3. Locate and select the desired JAR and click Open
JAR will appear in Referenced Libraries.
Method 3
Note that if you use this method, the external JAR must be in the same location on the hard drive as anyone using this project. This makes sharing projects more difficult.

Step 1. Right click the project name and go to Build Path

Step 2. Select Configure Build Path
.. and the project properties window will appear in your build path configuration.

Step 3. Select the Libraries label

Step 4. Click on Add External JARs
..

Step 5. Find and select the desired JAR and click Open
The JAR will now appear in the list of libraries in the build path.

Step 6. Click OK to close the properties window
JAR will now be inside Referenced Libraries.
Tips
- Whenever you add new files or folders to a project in Eclipse via anything other than Eclipse, you must reload (refresh) the associated project to notify Eclipse that the new files are there. Otherwise, you will encounter compiler or Build path errors.
- Even though the internal JAR disappeared from lib, the files are still in the file system. This is just Eclipse's way of telling you that the JAR files have been added.
-
Just to be safe, we recommend that you create a folder to document your code. Here's how:
- Right-click the. JAR in the Reference Libraries in the package explorer.
- Select the label Javadoc and type it in the folder(or URL) where your documentation is located. (Note: Eclipse won't like this and your validation will fail. Don't worry though, it'll still work).
- Select Java Source Attachment and find the folder or. JAR file that has your sources.