Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jar

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!

like image 349
Gian Segato Avatar asked May 03 '13 21:05

Gian Segato


2 Answers

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.

like image 153
mdierker Avatar answered Nov 13 '22 03:11

mdierker


As for the What question, the Twitter API property file contains configuration that is necessary for the Twitter jar to function. The file should probably be located on the classpath of your application.

And the How question, you can attach the javadoc jar file of the Twitter jar to the Twitter jar's classpath entry in Eclipse. Right-click your project and select Properties. Go to the Java Build Path entry and find the Twitter jar under the Libraries tab. If you expand the Twitter jar entry you will see 'JavaDoc location'. You can specify the javadoc jar there.

like image 28
Barry NL Avatar answered Nov 13 '22 01:11

Barry NL