I read the Java tutorials on Sun for JAR files, but I still can't find a solution for my problem. I need to use a class from a jar file called jtwitter.jar, I downloaded the file, and tried executing it (I found out yesterday that .jar files can be executed by double clicking on them) and Vista gave me an error saying "Failed to load Main-Class Manifest attribute from [path]/jtwitter.jar".
The guy who coded the .jar file wants me to import it, but where do I store the .jar file to import it in my code? I tried putting both the .jar file and my .java file in the same directory, didn't work.
The file I'm trying to work for is here: http://www.winterwell.com/software/jtwitter.php
I'm using JCreator LE.
Best Answer
Let's say we need to use the class
Classname
that is contained in the jar fileorg.example.jar
And your source is in the file
mysource.java
Like this:First, as you see, in your code you have to import the classes. To do that you need
import org.example.Classname;
Second, when you compile the source, you have to reference the jar file.
Please note the difference in using
:
and;
while compilingIf you are under a unix like operating system:
If you are under windows:
After this, you obtain the bytecode file
mysource.class
Now you can run this :
If you are under a unix like operating system:
If you are under windows: