Thread: stupid question about loading driver

stupid question about loading driver

From
Richard Welty
Date:
i have a standalone java application that i've been developing in netbeans
for a couple of months now. it's time that i got it working outside of the
netbeans IDE so that i can deploy a test box at the client site for them to
try and break.

i'm a relative novice at java, and the exercise in getting the code to work
outside of the ide has been interesting. right now, i'm stuck at a jdbc
driver problem. the driver loads up and runs fine with the program inside
of the ide. when the classes are in a jar file, the program fails with the
traditional error message (pardon the obfuscation of some names, but i'm
NDA'd here). since i just print an error message when i should also be
exiting when the driver isn't found, it goes on to fail when the driver
still isn't found (duh. i should probably fix that.).

$ /usr/java/j2sdk1.4.1_01/jre/bin/java -jar mosa.jar com.example.foo.ExampleFooApp
Using config file path: /home/rwelty/foo.cfg
ClassNotFoundException: org.postgresql.Driver
DBInstance: connecting to jdbc:postgresql://localhost:5432/foo-db
SQLException: No suitable driver
Exception in thread "main" java.lang.NullPointerException
        at com.example.foo.InstanceInfo.LoadSiteInfo(InstanceInfo.java:126)
        at com.example.foo.ExampleFooApp.main(MOSAScaleApp.java:8673)
$

the classpath looks fine to me, it includes the location of the correct
driver (the one that was working inside the IDE):

$ echo $CLASSPATH
/usr/java/j2sdk1.4.1_01/jre/lib/rt.jar:/usr/local/java/lib/pgjdbc2.jar
$

so what am i missing here?

thanks in advance,
  richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security

Re: stupid question about loading driver

From
Abel Muiño
Date:
El dom, 19-01-2003 a las 02:33, Richard Welty escribió:

> $ echo $CLASSPATH
> /usr/java/j2sdk1.4.1_01/jre/lib/rt.jar:/usr/local/java/lib/pgjdbc2.jar
> $
    Everything looks fine to me.

    Have you exported the classpath (i.e. "export CLASSPATH")? If you don't
do that, the CLASSPATH will NOT be set for all child processes (the
"java" process, in this case).

--
Abel Muiño Vizcaino


Re: stupid question about loading driver

From
Richard Welty
Date:
On Sun, 19 Jan 2003 12:40:13 +0100 Abel Mui=F1o <abel.muinho@mundo-r.com> w=
rote:

> El dom, 19-01-2003 a las 02:33, Richard Welty escribi=F3:
>=20
> > $ echo $CLASSPATH
> > /usr/java/j2sdk1.4.1_01/jre/lib/rt.jar:/usr/local/java/lib/pgjdbc2.jar
> > $
>         Everything looks fine to me.

>         Have you exported the classpath (i.e. "export CLASSPATH")? If you=
 don't
> do that, the CLASSPATH will NOT be set for all child processes (the
> "java" process, in this case).

i was pretty sure i had, but i made sure of it, and no change.

richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security

Re: stupid question about loading driver

From
Dave Cramer
Date:
ok,

Everything does look right here, so the only possibility that I can
think of is that the jar is spelled wrong, or isn't where you are saying
it is?

Dave
On Sun, 2003-01-19 at 09:58, Richard Welty wrote:
> On Sun, 19 Jan 2003 12:40:13 +0100 Abel Muiño <abel.muinho@mundo-r.com> wrote:
>
> > El dom, 19-01-2003 a las 02:33, Richard Welty escribió:
> >
> > > $ echo $CLASSPATH
> > > /usr/java/j2sdk1.4.1_01/jre/lib/rt.jar:/usr/local/java/lib/pgjdbc2.jar
> > > $
> >         Everything looks fine to me.
>
> >         Have you exported the classpath (i.e. "export CLASSPATH")? If you don't
> > do that, the CLASSPATH will NOT be set for all child processes (the
> > "java" process, in this case).
>
> i was pretty sure i had, but i made sure of it, and no change.
>
> richard
> --
> Richard Welty                                         rwelty@averillpark.net
> Averill Park Networking                                         518-573-7592
>               Unix, Linux, IP Network Engineering, Security
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Dave Cramer <Dave@micro-automation.net>


Re: stupid question about loading driver

From
Richard Welty
Date:
On 19 Jan 2003 10:14:27 -0500 Dave Cramer <Dave@micro-automation.net> wrote:
> Everything does look right here, so the only possibility that I can
> think of is that the jar is spelled wrong, or isn't where you are saying
> it is?

i cut and pasted it out of the classpath into an ls command, and the path
is correct.

this is my first cut at using ant and the jar builder tools, and i don't
know for a fact that i got the manifest.mf file right:

--cut here--
Manifest-Version: 0.1
Signature-Version: 0.1
Main-Class: com.example.foo.exampleFooApp
--cut here--

is the trivial one i'm using, modulo the obfuscation required by my NDA.

i had a classpath: entry in there, but removed it, it doesn't seem to make
a difference if it's there or not, but the documentation i went through is
mildly unclear about what form a classpath: entry in an manifest is
supposed to look like. should i have something like:

Classpath: org.postgresql.Driver

which is what i had before, or something else, or nothing at all? i can't
believe that they would want me to hardcode paths in the local file system
in to the manifest for a theoretically portable jar file.

richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security

Re: stupid question about loading driver

From
Anders Hermansen
Date:
* Richard Welty (rwelty@averillpark.net) wrote:
> $ /usr/java/j2sdk1.4.1_01/jre/bin/java -jar mosa.jar com.example.foo.ExampleFooApp
> Using config file path: /home/rwelty/foo.cfg
> ClassNotFoundException: org.postgresql.Driver
> DBInstance: connecting to jdbc:postgresql://localhost:5432/foo-db
> SQLException: No suitable driver
> Exception in thread "main" java.lang.NullPointerException
>         at com.example.foo.InstanceInfo.LoadSiteInfo(InstanceInfo.java:126)
>         at com.example.foo.ExampleFooApp.main(MOSAScaleApp.java:8673)
> $
>
> the classpath looks fine to me, it includes the location of the correct
> driver (the one that was working inside the IDE):
>
> $ echo $CLASSPATH
> /usr/java/j2sdk1.4.1_01/jre/lib/rt.jar:/usr/local/java/lib/pgjdbc2.jar
> $
>
> so what am i missing here?

When using the -jar command to start an application the CLASSPATH is
ignored.

I bet this will work:
/usr/java/j2sdk1.4.1_01/jre/bin/java -cp $CLASSPATH:mosa.jar com.example.foo.ExampleFooApp


Hope this helps,
Anders

--
Anders Hermansen
YoYo Mobile as

Re: stupid question about loading driver

From
Richard Welty
Date:
On Sun, 19 Jan 2003 18:29:13 +0100 Anders Hermansen <anders@yoyo.no> wrote:
> When using the -jar command to start an application the CLASSPATH is
> ignored.

> I bet this will work:
> /usr/java/j2sdk1.4.1_01/jre/bin/java -cp $CLASSPATH:mosa.jar
> com.example.foo.ExampleFooApp

bingo. that was it.

thanks everyone,
   richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security

Re: stupid question about loading driver

From
"Paul Stead"
Date:
.....My first reply rejected by the list.....

With stand-alone Java apps using the -jar I found any classpath passed in
was totally ignored and you *had* to pass them in via the manifest.  For
example, our e-mail server program has the following as the manifest:

Main-Class: com.envoysoftware.serverMain.emailenvoy
Class-Path: mail.jar activation.jar devpgjdbc2.jar

This is the ONLY way it would find the additional jar files UNLESS we put
them in the ext dir of the java distribution (i.e.
/path_to_java/jre/lib/ext/).  Note that you put the jar file names in the
manifest, NOT "org.postgresql.Driver".  Our jar files are in the same
directory as the main application, so we don't have full path names to them,
but I presume you'd need full paths if it wasn't there.

Hope this helps....it took me a day of pure frustration to figure this out!!
The Java documentation is NOT clear about this little tidbit on using
the -jar call.

cheers,
Paul



-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Richard Welty
Sent: Sunday, January 19, 2003 8:20 AM
To: PostgreSQL JDBC List
Subject: Re: [JDBC] stupid question about loading driver


On 19 Jan 2003 10:14:27 -0500 Dave Cramer <Dave@micro-automation.net> wrote:
> Everything does look right here, so the only possibility that I can
> think of is that the jar is spelled wrong, or isn't where you are saying
> it is?

i cut and pasted it out of the classpath into an ls command, and the path
is correct.

this is my first cut at using ant and the jar builder tools, and i don't
know for a fact that i got the manifest.mf file right:

--cut here--
Manifest-Version: 0.1
Signature-Version: 0.1
Main-Class: com.example.foo.exampleFooApp
--cut here--

is the trivial one i'm using, modulo the obfuscation required by my NDA.

i had a classpath: entry in there, but removed it, it doesn't seem to make
a difference if it's there or not, but the documentation i went through is
mildly unclear about what form a classpath: entry in an manifest is
supposed to look like. should i have something like:

Classpath: org.postgresql.Driver

which is what i had before, or something else, or nothing at all? i can't
believe that they would want me to hardcode paths in the local file system
in to the manifest for a theoretically portable jar file.

richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Re: stupid question about loading driver

From
Richard Welty
Date:
On Sun, 19 Jan 2003 10:19:58 -0800 Paul Stead <pstead@elementallogic.com> wrote:
> Hope this helps....it took me a day of pure frustration to figure this
> out!!
> The Java documentation is NOT clear about this little tidbit on using
> the -jar call.

quite. i have ca. $200 or $250 in java books on my desk, huge books that in
theory ought to cover just about everything, yet stuff like this is poorly
documented and hard to track down, either online or in the books. it's
quite aggravating.

i've chosen to use -cp instead of -jar per one of the other postings to
avoid the annoyance and potential non-portability of coding paths and jar
file names in the manifest.mf file.

thanks again,
  richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security

Re: stupid question about loading driver

From
Daniel Serodio
Date:
You could also put all your 'lib' jars in a lib/ directory, and use
relative paths in your manifest, like:

Classpath: lib/pgjdbc2.jar

[]'s
Daniel

On Sun, 2003-01-19 at 17:23, Richard Welty wrote:
> On Sun, 19 Jan 2003 10:19:58 -0800 Paul Stead <pstead@elementallogic.com> wrote:
> > Hope this helps....it took me a day of pure frustration to figure this
> > out!!
> > The Java documentation is NOT clear about this little tidbit on using
> > the -jar call.
>
> quite. i have ca. $200 or $250 in java books on my desk, huge books that in
> theory ought to cover just about everything, yet stuff like this is poorly
> documented and hard to track down, either online or in the books. it's
> quite aggravating.
>
> i've chosen to use -cp instead of -jar per one of the other postings to
> avoid the annoyance and potential non-portability of coding paths and jar
> file names in the manifest.mf file.
>
> thanks again,
>   richard
> --
> Richard Welty                                         rwelty@averillpark.net
> Averill Park Networking                                         518-573-7592
>               Unix, Linux, IP Network Engineering, Security
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
--
Daniel Serodio <daniel@checkforte.com.br>
CheckForte


Re: stupid question about loading driver

From
"Paul Stead"
Date:
With stand-alone Java apps using the -jar I found any classpath passed in
was totally ignored and you *had* to pass them in via the manifest.  For
example, our e-mail server program has the following as the manifest:

Main-Class: com.envoysoftware.serverMain.emailenvoy
Class-Path: mail.jar activation.jar devpgjdbc2.jar

This is the ONLY way it would find the additional jar files UNLESS we put
them in the ext dir of the java distribution (i.e.
/path_to_java/jre/lib/ext/).  Note that you put the jar file names in the
manifest, NOT "org.postgresql.Driver".  Our jar files are in the same
directory as the main application, so we don't have full path names to them,
but I presume you'd need full paths if it wasn't there.

Hope this helps....it took me a day of pure frustration to figure this out!!
The Java documentation is NOT clear about this little tidbit on using
the -jar call.

cheers,
Paul


-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Richard Welty
Sent: Sunday, January 19, 2003 8:20 AM
To: PostgreSQL JDBC List
Subject: Re: [JDBC] stupid question about loading driver


On 19 Jan 2003 10:14:27 -0500 Dave Cramer <Dave@micro-automation.net> wrote:
> Everything does look right here, so the only possibility that I can
> think of is that the jar is spelled wrong, or isn't where you are saying
> it is?

i cut and pasted it out of the classpath into an ls command, and the path
is correct.

this is my first cut at using ant and the jar builder tools, and i don't
know for a fact that i got the manifest.mf file right:

--cut here--
Manifest-Version: 0.1
Signature-Version: 0.1
Main-Class: com.example.foo.exampleFooApp
--cut here--

is the trivial one i'm using, modulo the obfuscation required by my NDA.

i had a classpath: entry in there, but removed it, it doesn't seem to make
a difference if it's there or not, but the documentation i went through is
mildly unclear about what form a classpath: entry in an manifest is
supposed to look like. should i have something like:

Classpath: org.postgresql.Driver

which is what i had before, or something else, or nothing at all? i can't
believe that they would want me to hardcode paths in the local file system
in to the manifest for a theoretically portable jar file.

richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org