Adding External Libraries to Eclipse Projects

Java comes with a virtual swiss army knife of tools and classes -- but it doesn't have everything. You can always build what you need from scratch, but sometimes -- if you are lucky -- someone, somewhere has already built what you need, and will graciously let you use it! As such things often involve many, many related individual java classes, interfaces, etc... (collectively called a java library) they are often shared via archive files called JAR files (short for "java archive"). A JAR file is not unlike the ZIP files seen frequently in email attachments, in that it is one or more files that have been compressed into a single, "as-small-as-possible" file.

If you do find yourself fortunate enough to have located an external JAR file for a java library that would help you in one of your projects, it is a simple matter to add it to your project so that you might take advantage of it's contents...

To demonstrate how this might be done by example, let us suppose that we want to be able to quickly and easily write and deploy programs with a graphical user interface. After some digging online, you discover a fellow by the name of Paul Oser has created a library of classes just for that purpose, and you download the corresponding breadboards.jar file to your local machine.

To add the functionality provided by this library to one of your projects, simply do the following:

  1. Start Eclipse, and locate the project folder to which this ACM library should be added.

  2. Right-click this project folder, and select "Build Path", and then select "Configure Build Path..."



  3. Select "Java Build Path" on the left, and then the "Libraries" tab. Click the "Classpath" line, and then click the "Add External JARS..." button



  4. Locate and select the "breadboards.jar" file you just downloaded, and then click "Open"



  5. Finally, click "Apply and Close" to close the dialog box. You will know that everything went ok if, when you open your project folder, you see an item called "Referenced Libraries", and upon expanding this item, you see the package "breadboards.jar" listed.

That's it -- simple, wasn't it!