Re: path and classpath settings

From: Lew <noone(at)lwsc(dot)ehost-services(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: path and classpath settings
Date: 2010-02-28 01:35:30
Message-ID: hmch90$91v$1@news.albasani.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

shilpa r wrote:
> am working on postgreSQL
> i [sic] wanted to know the path and CLASSPATH settings on the environbment
> variable of Xp

For JDBC, the PATH environment variable ("envar") is not relevant. While you
can include the PostgreSQL JDBC JAR file in the CLASSPATH, for most purposes
that is too much. The CLASSPATH envar affects every Java program that doesn't
override it, including in your case any that do not really need the Postgres
JDBC JAR.

Much better would be to use the "-classpath" or equivalent "-cp" option to the
"java" command line, or the equivalent if you are using an application server
like Tomcat or Glassfish. You should read up on the document for how to set
the classpath for a program within your environment, e.g., through the
tutorials and other documentation at java.sun.com.

> as am stuck up with an error stating ClassNotFoundException
> when am trying to connect to Database thru an java [sic] code

Do you have the JDBC JAR on your system? If not, it's available from
<http://jdbc.postgresql.org/>

After that, it's a matter of including it in the classpath the same way you
would any other library JAR:

ordinary command line: "-cp" as stated above

using "java -jar": in a directory relative to the application's JAR and
specified by that main JAR's manifest. (Using "java -jar" the JVM ignores any
CLASSPATH or "-classpath" specifications.)

Deploying to an application server: In the "WEB-INF/lib/" directory of the WAR
or the equivalent for an EAR.

It is a powerful thing to know how to specify the classpath for a Java program.

--
Lew

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Achilleas Mantzios 2010-03-01 15:31:15 severely wierd problem & PgSQL log analyzer
Previous Message John Abraham 2010-02-26 00:16:52 Re: NoSuchMethodError org.postgresql.core.QueryExecutor.startCopy(String)