How to Add JARs to Project Build Paths in Eclipse (Java)

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...

Part 1 of 5:

Adding Internal JARs

  1. images 1 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 1 of How to Add JARs to Project Build Paths in Eclipse (Java)
    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.
  2. images 2 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 2 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Copy and paste the JARs you need to lib. Select the JAR files you need and right-click them. Select them and click copy. Then paste them into the lib folder by clicking File then Paste or using Control or Command V.
  3. images 3 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 3 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Refresh your project. Do this by right-clicking the project name and selecting Refresh. The lib folder will now be visible in Eclipse with the JARs inside.
Part 2 of 5:

Configuring Your Build Path

  1. Expand the lib folder in Eclipse. Click the arrow to the left of the folder to expand it.
  2. images 4 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 4 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Select all the JARs you need. Hold Shift and click the JARs in the expanded folder.
  3. Right-click the JARs. This opens a pop-up menu to the right.
  4. images 5 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 5 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Navigate to Build Path. Placing the mouse cursor over "Build Path" displays a submenu to the left.
  5. Select Add to Build Path. The JARs will disappear from lib and reappear in Referenced Libraries.
Part 3 of 5:

Configuring Your Build Path (Alternative Method)

  1. Right-click the project name. This displays a pop-up menu to the right.
  2. images 6 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 6 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Navigate to Build Path. It's in the pop-up menu that displays when you right-click on the project name. This displays a sub-menu to the right.
  3. images 7 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 7 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Configure Build Path. The project properties window will appear showing your build path configurations.
  4. images 8 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 8 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Select the Libraries tab. It's at the top of the project properties window.
  5. images 9 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 9 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Add JARs. It's on the right side of the project properties window.
  6. images 10 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 10 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Select the JARs you want and click OK. The JARs will now appear in the list of libraries in the build path.
  7. images 11 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 11 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click OK to close the properties window. The JARs will now be in Referenced Libraries instead of lib.
Part 4 of 5:

Adding External JARs

  1. Right-click the project name. This displays a pop-up menu to the right.
    1. 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.
  2. images 12 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 12 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Navigate to Build Path. This displays a sub-menu to the right.
  3. images 13 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 13 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Configure Build Path. The project properties window will appear showing your build path configurations.
  4. images 14 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 14 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Add Variable. It's to the right of the project properties window.
  5. images 15 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 15 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Configure Variables. It's at the bottom of the New Variables window.
  6. images 16 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 16 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click New. It's at the bottom of the preferences window.
  7. images 17 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 17 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Type a name for the new variable. For example, if these are JARs for Tomcat, perhaps you could call it "TOMCAT_JARS".
  8. images 18 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 18 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Browse to the directory that contains the JAR for the path. Click the Folder button and browse to the directory that contains the JAR path.
    1. You can also Click File and select a specific jar file for the variable, if you prefer.
  9. images 19 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 19 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click OK. This defines the variables.
  10. images 20 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 20 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click OK. This closes the preferences dialog.
  11. images 21 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 21 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Select the variable from the list. Click the variable to select it.
  12. images 22 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 22 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Extend. It's the button to the right of the list of variables.
  13. images 23 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 23 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Select the JAR(s) that you want to add to the classpath. Click to select the JARs. Hold Shift to select multiple JARs.
  14. images 24 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 24 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click OK. This closes the extend dialog window.
  15. images 25 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 25 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click OK. This closes the new classpath variable dialog.
  16. images 26 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 26 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click OK. This closes the build path setup dialog.
    1. 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.

Adding External JARs (Alternative Method 1)

  1. Right-click the project name. This displays a pop-up menu to the side.
    1. Note: 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.
  2. images 27 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 27 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Navigate to Build Path. This displays a sub-menu to the right.
  3. images 28 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 28 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Add External Archives. It's in the Build Path sub-menu.

  4. images 29 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 29 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Select the JARs you want and click Open. The JARs will now appear in Referenced Libraries.
Part 5 of 5:

Adding External JARs (Alternative Method 2)

  1. Right-click the project name. This displays a pop-up menu to the right.
    1. Note: 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.
  2. images 30 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 30 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Navigate to Build Path. It's in the pop-up menu that appears when you right-click the project name.
  3. images 31 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 31 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Configure Build Path. The project properties window will appear showing your build path configurations.
  4. images 32 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 32 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Select the Libraries tab. It's at the top of the project properties window.
  5. images 33 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 33 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click Add External JARs. It's on the right side of the project properties window.
  6. images 34 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 34 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Select the JARs you want and click Open. The JARs will now appear in the list of libraries in the build path.
  7. images 35 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Images 35 of How to Add JARs to Project Build Paths in Eclipse (Java)
    Click OK to close the properties window. The JARs will now be in Referenced Libraries.
4.1 | 8 Vote
« PREV : How to Copy Files to...
How to Back up a... : NEXT »