When I run the code I get ClassNotFoundException.I thought it was because of ojdbc6.jar file.I downloaded the file from Oracle and copied the file to my subdirectory from where I am running the code on command line.However, I am still getting the error.Can anyone help me understanding what am I doing wrong?
You're having this problem because the class file that you try to run depends on a jar file called ojdbc6.jar. First , you need to compile both, the jar file and the class file.
1) First put your jar file in the same directory where you have your java code.
2) Then compile both, jar and java file:
javac -cp ".:/path_of_jar_file_found_using_pwd/ojdbc6.jar" MyJavaFile.java
3) Now run both as:
java -cp ojbdc6.jar:. MyJavaFile
This should work on mac/linux or other unix based system.For windows, replace :
by ;
.
From where are you running your program? From the screenshot, I can see that you are running it from terminal
Use the below command to run it from the terminal supplying the necessary jars which includes them in classpath for this particular run.
java -cp "Test.jar;lib/*" my.package.MainClass
If you want the necessary jars, you can set the classpath variable in windows by the below command and add necessary jars to the existing classpath variable
SET CLASSPATH = %CLASSPATH%;Test.jar;C:/username/Test1.jar
And then, you can run the java program normally
java SimpleInsert
If you are using an IDE like eclipse, NetBeams, you have to set up your build path and external jars in your build path.
Refer this post for more information Setting multiple jars in java classpath
As mentioned in my comment earlier, you might consider adding ojdbc6.jar
to your CLASSPATH
variable or you might add this jar under your %JAVA_HOME%\\jre\\lib\\ext
folder so that the extension
classloader will be able to load the necessary class file.
SET CLASSPATH = %CLASSPATH%;C:/JARS/ojdbc6.jar;
You can easily check whether the necessary class is part of your Application using CTRL + SHIFT + T
, as it identifies classes from added JARs as well.
Hope this helps!
Right-click on warning message --> Quick Fix;
Select the option Mark the associated raw classpath entry as a publish/export dependency. (in the following figure)
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.