1

I'm running this under windows vista cmd prompt:

java -classpath C:\postgresql-8.4-701.jdbc4.jar -jar myJar.jar

I get the error:

Cannot load postgresql driver. org.postgresql.Driver

The line causing the error is:

Class.forName("org.postgresql.Driver");

But in eclipse, the program works, and the postgresql library is referenced under the "Referenced Libraries".

How to fix this please ? I need to run the program under the windows cmd prompt while getting the same result I get in Eclipse IDE.

6
  • does your postgres jar file exist at that location c:\? Commented Jul 28, 2011 at 3:28
  • Do a jar -tf and confirm that it contains the org.postgresql.Driver class in it. Commented Jul 28, 2011 at 3:29
  • It doesn't contain it. So how can I fix this please ? Commented Jul 28, 2011 at 3:34
  • Find the jar file that you are using in Eclipse .. and replace this current one with that. Commented Jul 28, 2011 at 3:36
  • It is the same jar file already. Commented Jul 28, 2011 at 3:38

1 Answer 1

1

I think this has to do with the fact that since you are using an executable jar, the classpath variable is being ignored.

You should make sure that your myJar.jar has the correct classpath entries in its manifest file using

Class-Path: postgres...jar

Make sure that its in the same directory as myJar.jar

Sign up to request clarification or add additional context in comments.

1 Comment

To be precise: when using java -jar all other classpath definitions are ignored. That is also documented in the tools manual (see the last line for the -jar option): download.oracle.com/javase/6/docs/technotes/tools/windows/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.