How can i use jar file?

I have a jar file that contains some classes that I want to use in my project. I work on the command line, not in eclipse.

Please tell me how should I use these classes in the jar file for my project.

0
source share
3 answers

Use the -classpath command-line option:

javac -classpath library.jar MyProgram.java

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

java -classpath library.jar;. MyProgram

(Suppose you are using Windows. On Unix, use: instead, as a path separator.)

+6
source

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.

Java .

, , , .. .

- , (, ), , .

+1

You simply include it in your classpath as follows:

java -cp otherclasspath;thejar.jar yourlass
0
source

All Articles