java.lang.ClassNotFoundException: org.postgresql.Driver

前端 未结 2 1750
孤街浪徒
孤街浪徒 2020-12-07 06:17

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

相关标签:
2条回答
  • 2020-12-07 06:33

    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
    
    0 讨论(0)
  • 2020-12-07 06:34

    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

    0 讨论(0)
提交回复
热议问题