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

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

问题描述

每当我将我的项目构建为 jar(通过 NetBeans)时,它似乎不包含 postgresql 驱动程序库.我记得以前在以前版本的 NetBeans 和驱动程序上没有任何问题.我 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:UsersUsername>java -jar "C:UsersUsernameDocumentsNetBeansProjectsOrdersImportdistOrdersImport.jar" C:orderssometextfile.txt

在这一行中是否应该添加一些额外的东西来添加 postgresql-9.0-801.jdbc4.jar?我确实在项目内部将库包含到 lib 中,如果我直接从 NetBeans 运行它,它确实可以正常工作.我看过我以前的项目,它确实有效,似乎一切都一样,可悲的是我不记得了,请帮忙.

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 -cp postgresql-9.0-801.jdbc4.jar;OrdersImport.jar com.mypackage.MyMain C:orderssometextfile.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天全站免登陆