I'm using Netbeans 8.1 and maven, the project is as simple as connecting to a postgre DB and run a single query.
When I run the project from Netbeans, the System.out.println
message I set tells me that the connection to the db went successful, passing by the message in the below code "PostgreSQL JDBC Driver Registered!".
When the same project is ran in the Windows 7 prompt, like:
java -jar myproject.jar
The
try {
Class.forName("org.postgresql.Driver");
}
catch (ClassNotFoundException e) {
System.out.println("No PostgreSQL JDBC Driver found");
System.exit(0);
}
System.out.println("PostgreSQL JDBC Driver Registered!");
Jumps to the catch{}.
I can't explain why. Is somebody able to help me?
EDIT: If we could please stop marking this as duplicate, that'd be great. It may be argument for the classpath, but I do not want to use classpaths. Another application I am using, a variant of this one, simply run without modification to the classpath and does exactly the same Db connection.
There must be a way to achieve it, may be using the pom.xml or something else that I do not know
EDIT2: I'm quite sure that I edited this before, explaining that I found the way to have the program working without adding classpaths to the Windows command. the pom.xml was the key to configure the application. And no, the "duplicate answer" did not help me this time.