Sunday, 16 September 2012

How to add a JAR to Eclipse

As part of my learning Java I needed to add the acm package so I could follow along with some of the sample projects.  It's a bit fiddly, but easy enough to do, so I thought I'd post a quick step-by-step tutorial on how to do this in Eclipse:-

1)  Download the JAR you need.  In my case it was the acm package (which you can find here).
2)  Open Eclipse and add a folder to your project called 'lib' by right clicking the root folder of your project and selecting New>Folder.  Name it 'lib'
3)  Find the location of your downloaded JAR file and right-click>copy.
4)  Right-click and paste the file into your project's lib folder in Eclipse.

Note:  You can also drag and drop the jar file into the lib folder.  You will be asked whether you want to copy or link files.  I chose copy but I can see the benefits of linking.

5)  Now, right-click the jar file you've just pasted into the lib folder and select Build Path>Add To Build Path
6)  Your file will now show in a new folder called 'Referenced Libraries' and you can now import classes from the imported package.

Pretty easy, isn't it?

No comments:

Post a Comment