Reputation: 8985
I've been trying for an hour to run the following program with a the postgresql classpath
class Test{
public static void main(String[] args){
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnfe) {
System.err.println("Couldn't find Postgresql driver class!");
}
}
}
The program compiled fine with the javac command, but I'm having a hard time running it with the postgresql classpath. I have "postgresql-9.0-801.jdbc4.jar" in the same directory as the file and I tried the following, but non of them worked
java -classpath ./postgresql-9.0-801.jdbc4.jar Test
java -classpath postgresql-9.0-801.jdbc4.jar Test
java -classpath "postgresql-9.0-801.jdbc4.jar" Test
What am I doing wrong?
Upvotes: 3
Views: 10060
Reputation: 12368
command :java -cp .;postgresql-9.0-801.jdbc4.jar Test
both the jar and the class are in the same directory from which the command is run
Also make your class definition as public !!
Upvotes: 0
Reputation: 1319
When you specify the classpath you need to make sure it includes ALL of the class files your application needs, including the ones you create yourself. Assuming that Test.class is in the current directory along with the postgres Jar file, you need something like:
java -classpath postgresql-9.0-801.jdbc4.jar:. Test
See the Java Glossary for more details.
bm~
Upvotes: 8
Reputation: 52645
What is the error? ClassNotFoundException
for Test
or the postgres
library? If former, it is because you need to add Test in your classpath as well.
Assuming you are in the same directory where Test.class and the postgres jar is present,
java -classpath .:postgresql-9.0-801.jdbc4.jar Test
Upvotes: 3