Reputation: 5061
this will sound silly but i am executing my code from command prompt and have to use a jar in my class. I have placed my jar in lib folder of JDK.. but i am still getting error of file not found
any explanation??
EDITED : guys tried all but still not working
EDIT 2 :i am trying to work as was told by this link i am using js-1.6R5.jar
Edit 3 : i undestand all the things you ppl have told but nothing working for me.. pls give me a link to upload my example that i can share with you all.
Edit 4 : i am fed up by setting classpaths but its not working... i have SDK installed in my system, do i need an extra JDK to run my programs from command prompt??
Upvotes: 1
Views: 3276
Reputation: 597026
You can place it anywhere, as long is you include it in your classpath. See Setting the Class Path for how to include jars in the classpath.
Have in mind that adding something in the JDK lib is almost never a good idea.
Upvotes: 2
Reputation: 115328
Unfortunately your question contains a lot of question signs and few information.
If you are using java.io.File to open jar as a regular file this jar should not be in lib directory. You just have to provide correct path in file system.
If however you are just trying to use jar as a part of your application it should be in classpath. Use either command line java -cp myjar.jar
MyMainClassor put full path to this jar to global environment variable
CLASSPATH`.
Upvotes: 0
Reputation: 3582
A simple solution will be to place the jar fiel inside the windows folder if you are doing it in a Windows machine.
Upvotes: 0
Reputation: 47183
You can make a lib
folder in your application's directory and put jar
files there, then make your application find them by adding lib
to your application's classpath.
And, don't put your jar
files in JDK's lib
folder. It's not good practise.
Upvotes: 1
Reputation: 4860
You need to add the jar to the class path by doing the following...
java -classpath D:\myprogram;D:\myprogram\lib\supportLib.jar org.mypackage.HelloWorld
Please see Wikipedia - Classpath_(Java)
Upvotes: 3
Reputation: 11539
You need to let Java know that you want to include the jar in your classpath (the list of folders and jars it checks for classes). One way to do this is with the -cp
command line argument, something like
java -cp ".;pathToMyJar\myJar.jar" MyClass
Another is to edit the CLASSPATH environment variable in your OS to include your jar.
Upvotes: 0