I'm writing a java program which uses the Oracle JDBC driver. I've set it up in my classpath. When I run the program inside my IDE (added as jdbc as library) the program runs fine. When I try to deploy it, it totaly ignores the listing in classpath and gives me a NoClassDefFoundError.
I want to use the client's JDBC driver (the one installed) and don't supply my own. I package the program from JDeveloper, deployment as JAR File.
Running with: java -jar test.jar
When I put the library in %JAVA_HOME%/lib/ext it works properly.
Anyone knows how to resolve this issue?
You have 3 solutions: add this class in the path of your other compiled classes (respecting the package naming of your directories) add the root directory of this class in your classpath (in your case "C:\java\project\") add this single class into a jar and add this jar to the classpath.
Java Compiler and JVM (Java Virtual Machine) use CLASSPATH to locate the required files. If the CLASSPATH is not set, Java Compiler will not be able to find the required files and hence will throw the following error. The above error is resolved when CLASSPATH is set.
Setting CLASSPATH The CLASSPATH environment variable is modified with the set command. The format is: set CLASSPATH=path1;path2 ... The paths should begin with the letter specifying the drive, for example, C:\ .
To check our CLASSPATH on Windows we can open a command prompt and type echo %CLASSPATH%. To check it on a Mac you need to open a terminal and type echo $CLASSPATH.
When you run with java -jar
, the classpath is ignored.
You need to use the Class-Path
manifest property.
From http://download.oracle.com/javase/tutorial/deployment/jar/downman.html
You specify classes to include in the Class-Path header field in the manifest file of an applet or application. The Class-Path header takes the following form:
Class-Path: jar1-name jar2-name directory-name/jar3-name
From http://download.oracle.com/javase/1.4.2/docs/tooldocs/linux/java.html
-jar
...
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With