Adding an External Library to an Eclipse Project Folder

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 to web pages both console programs and programs with a graphical user interface. After some digging online, you discover the Association for Computing Machinery (ACM) has created a library of classes just for that purpose, and you download the corresponding acm.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 class folder, and select "Properties"

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

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

  5. Finally, click "OK" 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 "acm.jar" listed.

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