path and classpath settings

Поиск
Список
Период
Сортировка
Искать

path and classpath settings

От:
shilpa r <shilpar1800@gmail.com>
Дата:
Hello
 
am working on postgreSQL
i wanted to know the path and CLASSPATH settings on the environbment variable of Xp
as am stuck up with an error stating ClassNotFoundException
when am trying to connect to Database thru an java code
 
Kindly do the needful
 
 
Thanks and regards
Shilpa

Re: path and classpath settings

От:
Lew <noone@lwsc.ehost-services.com>
Дата:
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


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
FAQ