aspose file tools*
The moose likes Java in General and the fly likes ClassNotFoundException while executing using Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ClassNotFoundException while executing using "java -jar" command" Watch "ClassNotFoundException while executing using "java -jar" command" New topic
Author

ClassNotFoundException while executing using "java -jar" command

shahabas shabeer
Ranch Hand

Joined: Feb 23, 2004
Posts: 49
Hi,
I developed a java application.
My application connects to postgresql using a database driver(pg73jdbc2.jar).
The database driver jar file is there in my classpath.
My program worked as expected when I executed it using the command

java a.b.c.MyMainClass

Then I bundled my application in to a jar file.
When I tried to execute my program using the command,
java -jar MyJar.jar
it is complaining that the database Driver class(java.lang.ClassNotFoundException: org.postgresql.Driver) is not found.

I am sure that the driver jar is available in my class path and the program is working fine
when a execute it using "java a.b.c.MyMainClass" command

I also tried by copying the driver jar to my "jre/lib/ext" directory, but no luck

What could be the problem ?

Any help would be highly appreciated.

Shahabas E Shabeer
[ June 28, 2005: Message edited by: shahabas shabeer ]

The greatest pleasure in life is doing what peoples say you can not do.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Jar files are 'closed.' When you use the "-jar" option, the CLASSPATH (or the -cp switch) is ignored. Putting the driver in the /ext directory ought to work, though; or you can use

java -cp MyJar.jar;pg73jdbc2.jar a.b.c.MyMainClass


[Jess in Action][AskingGoodQuestions]
Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
hi,
is it possible to add class files to ext folder?
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException while executing using "java -jar" command
 
Similar Threads
jar an application using comm api
Where to put jdbc jar files
regular website updation. Is there any easy way ?
hoe to display text with 'justify' alignment..?
Connecting to the Java "derby" Netbeans database without Netbeans.