简体   繁体   中英

using Jar file in java code


I am coding in simple text document and executing java code with command line with javac command. i want to use jar file which is in directory like /abc/public/assi1 and i have code which is in directory like /abc/assi1. I am including the jar file with import statement in the class myClass.java which is in directory /abc/assi1/myClass.java i am getting errors.

It is not recognizing the things which are in the jar file.

Could some one please help in this.

Thanks

You can compile your code like this from the directory /abc/assi1:

 javac -cp .:/abc/public/assi1/your.jar -d . your-java-class.java

Then you can run your code like this from the directory /abc/assi1:

 java -cp .:/abc/public/assi1/your.jar your-java-class

-cp option sets the class path for you on command line. It adds the required jar file and the current directory . into your class path.

The jar has to be inside your java path.

You have to write something like this.

javac -classpath \path\to\lib.jar src.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM