Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java ignores classpath

Tags:

java

oracle

jdbc

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?

like image 586
ferdyh Avatar asked May 02 '11 14:05

ferdyh


People also ask

How do I fix a classpath problem?

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.

Is it necessary to set classpath in Java?

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.

How do I set the classpath in Java?

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:\ .

How do I know if my classpath is set correctly?

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.


1 Answers

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.

like image 87
Mike Samuel Avatar answered Sep 18 '22 05:09

Mike Samuel