java.lang.ClassNotFoundException loading JDBC driver

Lists: pgsql-jdbc
From: Ernst Jan Plugge <rmc(at)dds(dot)nl>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: java.lang.ClassNotFoundException loading JDBC driver
Date: 2003-02-09 21:27:24
Message-ID: Pine.LNX.4.44.0302092150370.3466-100000@hex.orbi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi,

Ik know this is a FAQ, but this looks different.

While loading the pgsql jdbc driver (using Class.forName() as the
documentation suggests) I get a ClassNotFoundException:

Exception in thread "main" java.lang.ClassNotFoundException:
org.postgresql.Driver

even though the JAR file _is_ on my classpath. I've tried both the
CLASSPATH environment variable, and the -cp command line argument. The
test app I use is extremely bare bones, uses nothing beyond JDBC, and only
tries to load the driver and establish a connection.

If I try to execute the class org.postgresql.Driver directly, with the
same classpath specification, the class is found, and I get (as expected)
an error message saying the class has no main method. This suggests that
my classpath is okay.

If I move the JAR file into the JVM's lib/ext directory, things work
perfectly. I need to be able to use the driver without doing that,
however. What am I doing wrong?

I'm using the pg73jdbc3.jar from jdbc.postgresql.org, downloaded today.
My JVM is j2sdk1.4.1_01 from Sun, on Red Hat Linux 8.0

I also tried the 7.2, 7.1 and 7.0 drivers, and JVM jdk1.3.1_06 from Sun.
(I used pg73jdbc2.jar instead of pg73jdbc3.jar there)

My test app is very simple:

import java.sql.*;

public class TestApp
{
public static void main( String argv[] ) throws
java.sql.SQLException, java.lang.ClassNotFoundException
{
Class.forName( "org.postgresql.Driver" );
String url = "jdbc:postgresql://dbhost:5432/test";
Connection conn = DriverManager.getConnection( url, "test", "xxxxxxxx" );
}
}

Ernst Jan


From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: Ernst Jan Plugge <rmc(at)dds(dot)nl>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: java.lang.ClassNotFoundException loading JDBC driver
Date: 2003-02-10 16:19:46
Message-ID: 1044893985.1028.126.camel@inspiron.cramers
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Ernst,

try running with java -d to show debugging information, it will show you
the classpath it is using

Dave
On Sun, 2003-02-09 at 16:27, Ernst Jan Plugge wrote:
> Hi,
>
>
> Ik know this is a FAQ, but this looks different.
>
> While loading the pgsql jdbc driver (using Class.forName() as the
> documentation suggests) I get a ClassNotFoundException:
>
> Exception in thread "main" java.lang.ClassNotFoundException:
> org.postgresql.Driver
>
> even though the JAR file _is_ on my classpath. I've tried both the
> CLASSPATH environment variable, and the -cp command line argument. The
> test app I use is extremely bare bones, uses nothing beyond JDBC, and only
> tries to load the driver and establish a connection.
>
> If I try to execute the class org.postgresql.Driver directly, with the
> same classpath specification, the class is found, and I get (as expected)
> an error message saying the class has no main method. This suggests that
> my classpath is okay.
>
> If I move the JAR file into the JVM's lib/ext directory, things work
> perfectly. I need to be able to use the driver without doing that,
> however. What am I doing wrong?
>
> I'm using the pg73jdbc3.jar from jdbc.postgresql.org, downloaded today.
> My JVM is j2sdk1.4.1_01 from Sun, on Red Hat Linux 8.0
>
> I also tried the 7.2, 7.1 and 7.0 drivers, and JVM jdk1.3.1_06 from Sun.
> (I used pg73jdbc2.jar instead of pg73jdbc3.jar there)
>
> My test app is very simple:
>
> import java.sql.*;
>
> public class TestApp
> {
> public static void main( String argv[] ) throws
> java.sql.SQLException, java.lang.ClassNotFoundException
> {
> Class.forName( "org.postgresql.Driver" );
> String url = "jdbc:postgresql://dbhost:5432/test";
> Connection conn = DriverManager.getConnection( url, "test", "xxxxxxxx" );
> }
> }
>
>
> Ernst Jan
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
--
Dave Cramer <Dave(at)micro-automation(dot)net>


From: Ernst Jan Plugge <rmc(at)dds(dot)nl>
To: Dave Cramer <Dave(at)micro-automation(dot)net>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: java.lang.ClassNotFoundException loading JDBC driver
Date: 2003-02-10 21:34:43
Message-ID: Pine.LNX.4.44.0302102213170.15589-100000@hex.orbi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On 10 Feb 2003, Dave Cramer wrote:

> Ernst,
>
> try running with java -d to show debugging information, it will show you
> the classpath it is using

That option isn't recognized by the JVM I'm using.

Anyway, my problem's been solved by another reader. Note to self:

Rule #1: Just because you've read the docs, doesn't mean you actually know
everything in there.

Rule #2: The following two are _not_ equivalent:

export CLASSPATH=.:foo.jar
java -jar bar.jar

export CLASSPATH=.:foo.jar:bar.jar
java MainClass

Where MainClass is the main class in bar.jar.

I'm not yet 100% confident on the semantics of class loading, but I know a
little more than I did yesterday, which is always a good thing :-)

Thanks.

Ernst Jan

>
> Dave
> On Sun, 2003-02-09 at 16:27, Ernst Jan Plugge wrote:
> > Hi,
> >
> >
> > Ik know this is a FAQ, but this looks different.
> >
> > While loading the pgsql jdbc driver (using Class.forName() as the
> > documentation suggests) I get a ClassNotFoundException:
> >
> > Exception in thread "main" java.lang.ClassNotFoundException:
> > org.postgresql.Driver
> >
> > even though the JAR file _is_ on my classpath. I've tried both the
> > CLASSPATH environment variable, and the -cp command line argument. The
> > test app I use is extremely bare bones, uses nothing beyond JDBC, and only
> > tries to load the driver and establish a connection.
> >
> > If I try to execute the class org.postgresql.Driver directly, with the
> > same classpath specification, the class is found, and I get (as expected)
> > an error message saying the class has no main method. This suggests that
> > my classpath is okay.
> >
> > If I move the JAR file into the JVM's lib/ext directory, things work
> > perfectly. I need to be able to use the driver without doing that,
> > however. What am I doing wrong?
> >
> > I'm using the pg73jdbc3.jar from jdbc.postgresql.org, downloaded today.
> > My JVM is j2sdk1.4.1_01 from Sun, on Red Hat Linux 8.0
> >
> > I also tried the 7.2, 7.1 and 7.0 drivers, and JVM jdk1.3.1_06 from Sun.
> > (I used pg73jdbc2.jar instead of pg73jdbc3.jar there)
> >
> > My test app is very simple:
> >
> > import java.sql.*;
> >
> > public class TestApp
> > {
> > public static void main( String argv[] ) throws
> > java.sql.SQLException, java.lang.ClassNotFoundException
> > {
> > Class.forName( "org.postgresql.Driver" );
> > String url = "jdbc:postgresql://dbhost:5432/test";
> > Connection conn = DriverManager.getConnection( url, "test", "xxxxxxxx" );
> > }
> > }
> >
> >
> > Ernst Jan
> >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>


From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: Ernst Jan Plugge <rmc(at)dds(dot)nl>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: java.lang.ClassNotFoundException loading JDBC driver
Date: 2003-02-10 21:37:51
Message-ID: 1044913071.1028.146.camel@inspiron.cramers
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Ernst,

When you specify a jar then the classpath environment variable is NOT
used.

Dave
On Mon, 2003-02-10 at 16:34, Ernst Jan Plugge wrote:
> On 10 Feb 2003, Dave Cramer wrote:
>
> > Ernst,
> >
> > try running with java -d to show debugging information, it will show you
> > the classpath it is using
>
> That option isn't recognized by the JVM I'm using.
>
>
> Anyway, my problem's been solved by another reader. Note to self:
>
> Rule #1: Just because you've read the docs, doesn't mean you actually know
> everything in there.
>
> Rule #2: The following two are _not_ equivalent:
>
> export CLASSPATH=.:foo.jar
> java -jar bar.jar
>
> export CLASSPATH=.:foo.jar:bar.jar
> java MainClass
>
> Where MainClass is the main class in bar.jar.
>
>
> I'm not yet 100% confident on the semantics of class loading, but I know a
> little more than I did yesterday, which is always a good thing :-)
>
> Thanks.
>
>
> Ernst Jan
>
>
> >
> > Dave
> > On Sun, 2003-02-09 at 16:27, Ernst Jan Plugge wrote:
> > > Hi,
> > >
> > >
> > > Ik know this is a FAQ, but this looks different.
> > >
> > > While loading the pgsql jdbc driver (using Class.forName() as the
> > > documentation suggests) I get a ClassNotFoundException:
> > >
> > > Exception in thread "main" java.lang.ClassNotFoundException:
> > > org.postgresql.Driver
> > >
> > > even though the JAR file _is_ on my classpath. I've tried both the
> > > CLASSPATH environment variable, and the -cp command line argument. The
> > > test app I use is extremely bare bones, uses nothing beyond JDBC, and only
> > > tries to load the driver and establish a connection.
> > >
> > > If I try to execute the class org.postgresql.Driver directly, with the
> > > same classpath specification, the class is found, and I get (as expected)
> > > an error message saying the class has no main method. This suggests that
> > > my classpath is okay.
> > >
> > > If I move the JAR file into the JVM's lib/ext directory, things work
> > > perfectly. I need to be able to use the driver without doing that,
> > > however. What am I doing wrong?
> > >
> > > I'm using the pg73jdbc3.jar from jdbc.postgresql.org, downloaded today.
> > > My JVM is j2sdk1.4.1_01 from Sun, on Red Hat Linux 8.0
> > >
> > > I also tried the 7.2, 7.1 and 7.0 drivers, and JVM jdk1.3.1_06 from Sun.
> > > (I used pg73jdbc2.jar instead of pg73jdbc3.jar there)
> > >
> > > My test app is very simple:
> > >
> > > import java.sql.*;
> > >
> > > public class TestApp
> > > {
> > > public static void main( String argv[] ) throws
> > > java.sql.SQLException, java.lang.ClassNotFoundException
> > > {
> > > Class.forName( "org.postgresql.Driver" );
> > > String url = "jdbc:postgresql://dbhost:5432/test";
> > > Connection conn = DriverManager.getConnection( url, "test", "xxxxxxxx" );
> > > }
> > > }
> > >
> > >
> > > Ernst Jan
> > >
> > >
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
> >
--
Dave Cramer <Dave(at)micro-automation(dot)net>