If your Java project requires a JAR (Java Archive) library to function, you need to configure your project to include the libraries in the build path. Fortunately, Eclipse makes this process simple and easy to remember. The build version used in this article is Eclipse Java - Ganymede 3.4.0.
Steps
Add JAR internally
Copy the JAR file you will be using for your project.library
library
Reloadlibrary
Method 1

Open lib in Eclipse and select all the JAR files you need.

Right-click on the JAR and point to Build Path.

Select Add to Build Path. The JAR will disappear from lib and reappear in Referenced Libraries (Referenced Libraries).
Method 2

Right-click on the project name and point to Build Path (Build Path).

Select Configure Build Path... and the project's Properties window will appear for you to customize the build path.

Select the Libraries tab.

Click Add JARs... (Add JAR)

Search for and select the desired JAR, then click OK. The JAR will now appear in the list of libraries in the build path.

Click OK to close the Properties window. The JAR will now be located in Referenced Libraries instead of lib.
Add External JAR
Note: It is better to reference JARs that are within your project or another project – this helps you track all dependencies in version control. (You are using a version control system, right?). Use one of the methods below.
Method 1
This method is preferred because it allows multiple developers on the same project to search for external JARs in different locations.

Right-click on the project name and point to Build Path.

Select Configure Build Path... and the project's Properties window will appear, allowing you to customize your build path.

Click Add Variable... (Add variable)

Click Configure Variables... (Customize variables)

Click New... (New variable)

Enter a name for the new variable. For example, if it's a Tomcat JAR, you could name it TOMCAT_JARS

Navigate to the directory containing the JAR to use as the path. (You can also select a specific jar file for the variable if desired).

Click Ok to define the variable.

Click Ok to close the options dialog.

Select the variable from the list.

Click Extend... (Expand)

Select one or more JAR files that you wish to add to the classpath variable.

Click Ok to close the extended dialog box.

Click Ok to close the new classpath variable dialog box.

Click Ok to close the build path settings dialog.
- If you share the project with others, they will also need to define the variable. They can define it under
Window->Preferences->Java->Build Path->Classpath Variables
Method 2
Chú ý rằng nếu bạn dùng phương pháp này, JAR bên ngoài phải nằm ở cùng vị trí trên ổ cứng của mọi người thực hiện dự án. Điều này có thể khiến việc chia sẻ dự án chung trở nên khó khăn hơn.

Nhấp chuột phải vào tên dự án và trỏ vào Build Path.

Lựa chọn Add External Archives... (Thêm Archive bên ngoài)

Tìm kiếm và lựa chọn JAR bạn muốn rồi nhấp Open (Mở). JAR giờ sẽ xuất hiện trong Referenced Libraries (Thư viện được tham chiếu).
Phương pháp 3
Note that if you choose this method, the external JAR must be located at the same path on the hard drive of anyone working on the project. This could make sharing the project among team members more challenging.

Right-click on the project name and navigate to Build Path (Build Path).

Click Configure Build Path... and the project's Properties window will open to customize your build path.

Select the Libraries (Libraries) tab.

Click Add External JARs... (Add External JAR)

Search for and select the desired JAR, then click Open. The JAR will now appear in the library list of the build path.

Click OK to close the Properties window. The JAR will now be located under Referenced Libraries.
Tip
- Every time you add a file or folder to your project in Eclipse through anything other than Eclipse itself, you must refresh the affected projects so that Eclipse can detect the new files. Otherwise, you may encounter compile errors or build path issues.
- Even if a JAR inside disappears from lib, it still exists in the file system. This is just Eclipse's way of letting you know that those JARs have been added.
- For safety, you may need to create a folder to write notes for your code in the text. Here's how to do it:
- Right-click on the .JAR in the Referenced Libraries in the package explorer.
- Select the Javadoc tab and enter the folder (or URL) containing the documentation. (Note: Eclipse doesn't like this, and the validation process will fail. However, don't worry because it will still work.)
- Select Java Source Attachment and locate the folder or .JAR file containing the source.