Whenever I build my project as jar(via NetBeans) it seems that it does not include the postgresql driver library. I remember doing it before without any problems on previous
You would have to add the postgre jar to your classpath:
C:\Users\Username>java -classpath "location of postgresql-9.0-801.jdbc4.jar" -jar "C:\Users\Username\Documents\NetBeansProjects\OrdersImpo rt\dist\OrdersImport.jar" C:\orders\sometextfile.txt
There should be an entry in your MANIFEST.MF file that references the Postgres driver. And the driver needs to copied so that it's reachable from the real jar files location.
So your MANIFEST.MF needs to include something like this:
Class-Path: lib/postgresql-9.0-801.jdbc4.jar
If the JDBC driver is part of your NetBeans project, NetBeans should have copied it to dist/lib.
If you don't want to change the manifest file (or cannot), you need to manually reference all needed libraries on the command line. But then you cannot use the -jar
option any longer:
java -cp postgresql-9.0-801.jdbc4.jar;OrdersImport.jar com.mypackage.MyMain C:\orders\sometextfile.txt
Remember that you have to specify the main class when using -cp or -classpath