tags:

views:

56

answers:

3

I have a jar file which contains some classes those which i want to use in my project. I am working in command line and not in eclipse.

Please tell me how i should use those classes in the jar file for my project.

+5  A: 

Use the -classpath command line option:

javac -classpath library.jar MyProgram.java

And then to run it, specify the classpath again - including where your actual code is:

java -classpath library.jar;. MyProgram

(That's assuming you're using Windows. On Unix use : instead of ; as that's the path separator.)

Jon Skeet
+1  A: 

Jar file is a way to package java classes. To use the classes in the jar file, you need to include the jar in your classpath.

You need to then import the required class(es) in your java code and access them.

Of course you need to know how to use these classes i.e. what public methods etc. they expose.

If these jars correspond to some 3rd party library, you need to check the documentation (maybe on the web) to see how to use the classes.

Rahul
A: 

You just include it to your classpath like this:

java -cp otherclasspath;thejar.jar yourlass
NawaMan