|
Quote:
|
|
I've noted that the machine on which java is installed does not have any value for the environment variable 'CLASSPATH'.
|
The classpath (the list of locations from where the java tools will locate classes and resources) and the operating system CLASSPATH environment variable are related, but different, things. The tools will use the environment variable to determine the classpath they use
but only if there is no classpath specified as part of the command used to run them.
Usually you would specify the classpath as part of the command used to launch the java tool and would not rely on the existence or particular value of CLASSPATH.
You can use the -cp switch for this.
So if you were compiling from the directory containing the source you could use:
|
Code:
|
javac -cp .:/path/to/postgresql-8.3-604.jdbc4.jar mypackage/MyApp.java
java -cp .:/path/to/postgresql-8.3-604.jdbc4.jar mypackage.MyApp |
As suggested by that example the postgresql jar can be put anywhere you like. Mentioning it as part of the command to compile or run
makes it part of the classpath. (And, incidently, that's what you usually want: you want the jar to become part of the classpath not to be located somewhere on the classpath.)
If you haven't done so, read the fine manual which in this case includes an informative discussion of
How Classes Are Found.
EDIT:
A Windows translation of the commands might be
|
Code:
|
javac -cp .;\path\to\postgresql-8.3-604.jdbc4.jar mypackage\MyApp.java
java -cp .;\path\to\postgresql-8.3-604.jdbc4.jar mypackage.MyApp |
-cp and -classpath are synonymous. Mind the dot.