How to Add JARs to Project Build Paths in Eclipse (Java)
Two Methods:Adding Internal JARsAdding External JARs
When your Java project requires JAR libraries (Java Archive) to function, you have to configure your project to include the libraries in its build path. Fortunately, Eclipse makes this process simple and easy to remember. The build used here is Eclipse Java - Ganymede 3.4.0.
Steps
Method 1 of 2: Adding Internal JARs
-
1Copy the JARs you'll be using to your project. Here's how it's conventionally done:
- Create a new folder named lib in your project folder. This stands for "libraries" and will contain all the JARs you'll be using for that project.
- Copy the JARs you need to lib.
- Refresh your project by right clicking the project name and selecting Refresh. The lib folder will now be visible in Eclipse with the JARs inside.
Ad -
2Complete either of the following methods to finish configuring your build path.
Method 1
-
1Expand lib in Eclipse and select all the JARs you need.
-
2Right-click the JARs and navigate to Build Path.
-
3Select Add to Build Path. The JARs will disappear from lib and reappear in Referenced Libraries.
Method 2
-
1Right click the project name and navigate to Build Path.
-
2Select Configure Build Path... and the project properties window will appear showing your build path configurations.
-
3Select the Libraries tab.
-
4Click Add JARs...
-
5Locate and select the JARs you want and click OK. The JARs will now appear in the list of libraries in the build path.
-
6Click OK to close the properties window. The JARs will now be in Referenced Libraries instead of lib.
Method 2 of 2: Adding External JARs
Note: It is much better to reference JARs that exist in your project or in other projects - this allows you to check in all of your dependencies to your version control system. (You are using version control, right?)
Use one of the following methods.
Method 1
This is the preferred method, as it allows different developers of a common project to locate their external jars in different places.
-
1Right click the project name and navigate to Build Path.
-
2Select Configure Build Path... and the project properties window will appear showing your build path configurations.
-
3Click Add Variable...
-
4Click Configure Variables...
-
5Click New...
-
6Type a name for the new variable. For example, if these are JARs for Tomcat, perhaps call it TOMCAT_JARS
-
7Browse to the directory that contains the JAR for the path. (You can also select a specific jar file for the variable, if you prefer.)
-
8Click Ok to define the variable.
-
9Click Ok to close the preferences dialog.
-
10Select the variable from the list.
-
11Click Extend...
-
12Select the JAR(s) that you want to add to the classpath.
-
13Click Ok to close the extend dialog.
-
14Click Ok to close the new classpath variable dialog.
-
15Click Ok to close the build path setup dialog.
- If you share the project with someone else, they must also define the variable. They can define it under
Window->Preferences->Java->Build Path->Classpath Variables
Ad - If you share the project with someone else, they must also define the variable. They can define it under
Method 2
Note that if you use this method, the external JAR will need to be in the same location on the hard drive for anyone who uses this project. This can make sharing a common project more difficult.
-
1Right click the project name and navigate to Build Path.
-
2Select Add External Archives...
-
3Locate and select the JARs you want and click Open. The JARs will now appear in Referenced Libraries.Ad
Method 3
Note that if you use this method, the external jar will need to be in the same location on the hard drive for anyone who uses this project. This can make sharing a common project more difficult.
-
1Right-click the project name and navigate to Build Path.
-
2Select Configure Build Path... and the project properties window will appear showing your build path configurations.
-
3Select the Libraries tab.
-
4Click Add External JARs...
-
5Locate and select the JARs you want and click Open. The JARs will now appear in the list of libraries in the build path.
-
6Click OK to close the properties window. The JARs will now be in Referenced Libraries.Ad
We could really use your help!
relationships?

laundry and cleaning?

dogs?

caring for burns?

Tips
- Whenever you add new files or folders to your projects in Eclipse via anything but Eclipse, you must refresh the affected projects to let Eclipse know that the new files are there. Otherwise you may run into compiler or build path errors.
- Though the internal JARs disappear from lib, they are still there in the file system. It is merely Eclipse's perspective telling you that those JARs have been added.
- To be safe, you might want to create a folder in order to document your code. Here's how to do it:
- Right-click the .JAR in the Reference Libraries in the package explorer.
- Select Javadoc tab and type in the folder (or URL) where the documentation is located. (Note: Eclipse will not like this and validation will fail. But don't worry, it will sill work.)
- Select Java Source Attachment and find the folder or .JAR file containing sources.
Article Info
Categories: Java | File Manipulation
In other languages:
Español: Cómo añadir un jar a un proyecto en eclipse (java), Italiano: Come Aggiungere un JAR a un Progetto Java in Eclipse, Português: Como Adicionar JARs nos Caminhos de Acesso de Projeto em Eclipse (Java), Русский: добавить библиотеки JAR в проект на Eclipse (Java)
Thanks to all authors for creating a page that has been read 795,259 times.
About this wikiHow