Java – How to use *.jar file in a Java project

jarjava

I'm a complete novice to Java, and I'm stuck in trying to use an external jar library in a Java project I'm working on.

The library is Twitter4J (http://twitter4j.org/), a complex group of files which I can't understand how to include. I'm using Eclipse on Windows. I understood the meaning of CLASSPATH enviroment variable (or well, I think I did), but I can't understand how to link it to the Eclipse enviroment.

This blog post seemed to be what I was looking for: http://jasperpeilee.wordpress.com/2012/01/25/how-to-set-up-twitter4j-quickly-in-your-java-project/

But:

Add twitter4j-core-2.2.5.jar into project for general use.

1) Where should I copy the core file? In the /bin/ folder? Or in a completly unrelated /lib/ folder, as this question in SO stated?

Copy Twitter API property file into your project/bin directory.

2) What is the Twitter API property file?

3) How can I include JavaDoc jar files too? Is it possibile to get them into Elipse?

Any kind of help, even just a link, will be very appreciated!

Best Solution

You probably have a project folder for your Eclipse project. Go ahead and make a lib folder inside of your project folder, in the same directory as src and bin. There's nothing special about the lib folder specifically, it's just a convenient name. Copy the .jar file into your newly created folder. Back in Eclipse, right click your project and click Refresh. The lib folder should pop up, including your JAR! Right click the JAR file and go to Build Path --> Add To Build Path. At this point, any class in the project should be able to use Twitter4J features.