抛出java.lang.ClassNotFoundException:org.postgresql.Driver [英] java.lang.ClassNotFoundException: org.postgresql.Driver

查看:5660
本文介绍了抛出java.lang.ClassNotFoundException:org.postgresql.Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我建我的项目作为JAR(通过NetBeans的),它似乎不包括PostgreSQL的驱动程序库。我记得以前这样做不会对NetBeans和驱动程序的previous版本的任何问题。我CMD运行是这样的:

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 versions of NetBeans and Drivers. I cmd run something like:

C:\Users\Username>java -jar "C:\Users\Username\Documents\NetBeansProjects\OrdersImport\dist\OrdersImport.jar" C:\orders\sometextfile.txt

如果有额外的东西在此行中添加PostgreSQL相关9.0-801.jdbc4.jar包括?我没有包括库项目的内部lib和它的工作没有任何麻烦,如果我从NetBeans中直接运行它。我看它做的工作我的previous项目,似乎一切都一样,可怜我只是不记得了,请帮助。

Should there be something extra to include in this line to add postgresql-9.0-801.jdbc4.jar? I did include library to lib inside of the project and it does work without any troubles if I run it from NetBeans directly. I've looked at my previous project where it did work, seems to be everything same, pathetic I just can't remember, help please.

推荐答案

有应该在你的MANIFEST.MF文件引用的Postgres驱动程序的条目。而驱动程序需要复制以便它离真正的jar文件的位置到达。

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.

所以,你的MANIFEST.MF需要包括这样的事情:

So your MANIFEST.MF needs to include something like this:

类路径:LIB / PostgreSQL的-9.0-801.jdbc4.jar

Class-Path: lib/postgresql-9.0-801.jdbc4.jar

如果JDBC驱动程序是NetBeans项目的一部分,NetBeans的应该有其复制到DIST / lib中。

If the JDBC driver is part of your NetBeans project, NetBeans should have copied it to dist/lib.

如果您不希望更改清单文件(或不能),您需要手动引用在命令行上所有所需的库。但你不能使用 -jar 选项不再:

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命令的PostgreSQL-9.0-801.jdbc4.jar; OrdersImport.jar com.mypackage.MyMain C:\\命令\\ sometextfile.txt

请记住,你必须指定主类使用-cp时或-classpath

Remember that you have to specify the main class when using -cp or -classpath

这篇关于抛出java.lang.ClassNotFoundException:org.postgresql.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆