java jar 类路径错误帮助

发布于 2024-11-26 04:49:29 字数 1258 浏览 1 评论 0原文

因此,我在文件夹 C:\folder\folderbaby 中设置了一个可执行 jar,

该 jar 包含使用 jdbc 对 mysql 的一大堆调用

如果我从命令行进入 C:\folder\folderbaby,然后运行 ​​java,则 - jar thejar.jar,它会正常运行并访问数据库,

但是如果我 cd 到 C:\ 然后运行 ​​java -jar C:\folder\folderbaby\thejar.jar,它将返回一大堆错误:

Trying to add database driver (JDBC): RmiJdbc.RJDriver - Error, not in CLASSPATH
?
Trying to add database driver (JDBC): jdbc.idbDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): com.mckoi.JDBCDriver - Error, not in CLASS
PATH?
Trying to add database driver (JDBC): org.hsqldb.jdbcDriver - Error, not in CLAS
SPATH?
java.sql.SQLException: No suitable driver found for jdbc:idb=experiments.prp
java.lang.IllegalStateException: Not connected, please connect first!
false

首先,jar 需要一个 .prop 文件,其中包含有关要访问的数据库的信息。 prop 文件包含在 jar 本身内部...我猜错误是存在的,因为即使 prop 文件位于 jar 内部,它也找不到 prop 文件,

我该如何解决这个问题,以便即使 jar 可以调用来自它所在目录之外的目录?

##################编辑:Manifest.MF########################的内容###

Manifest-Version: 1.0
Rsrc-Class-Path: ./ mysql-connector-java-5.1.17-bin.jar weka-src.jar weka.jar j.jar
Class-Path: .
Rsrc-Main-Class: Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

so I set up an executable jar that is in folder C:\folder\folderbaby

the jar contains a whole bunch of calls to mysql using jdbc

if I go from the command line and cd to C:\folder\folderbaby and then run java -jar thejar.jar, it would run properly and access the database just fine

but then if I cd to C:\ and then run java -jar C:\folder\folderbaby\thejar.jar, it would return a whole bunch of errors:

Trying to add database driver (JDBC): RmiJdbc.RJDriver - Error, not in CLASSPATH
?
Trying to add database driver (JDBC): jdbc.idbDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): com.mckoi.JDBCDriver - Error, not in CLASS
PATH?
Trying to add database driver (JDBC): org.hsqldb.jdbcDriver - Error, not in CLAS
SPATH?
java.sql.SQLException: No suitable driver found for jdbc:idb=experiments.prp
java.lang.IllegalStateException: Not connected, please connect first!
false

First of all the jar requires a .prop file that contains information about the database to access. The prop file is contained inside the jar itself...I guess the error is there because it couldn't find the prop file even though the prop file is inside the jar

how would I go about fixing this so that the jar is callable even from directory outside where it is contained?

##################EDIT: Content of Manifest.MF#########################

Manifest-Version: 1.0
Rsrc-Class-Path: ./ mysql-connector-java-5.1.17-bin.jar weka-src.jar weka.jar j.jar
Class-Path: .
Rsrc-Main-Class: Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

将军与妓 2024-12-03 04:49:29

我相信问题在于 Manifest 行 Rsrc-Class-Path 是 Eclipse 扩展(它不是 Oracle 的 Jar 文件规范的一部分),并且需要在运行时解析的 jar 文件而是在 Class-Path 行上。

I believe the problem is that the Manifest line Rsrc-Class-Path is an Eclipse extension (it's not part of the Jar file spec from Oracle), and the jar files to be resolved at runtime need to be on the Class-Path line instead.

叫思念不要吵 2024-12-03 04:49:29

您应该使用

java -classpath C:\folder\folderbaby -jar C:\folder\folderbaby\thejar.jar

这将设置类路径,然后运行您请求的 jar。默认情况下,java 使用当前目录作为类路径,当您移动到不同的文件夹时,它无法看到 jar 所在的位置。

You should use

java -classpath C:\folder\folderbaby -jar C:\folder\folderbaby\thejar.jar

This will set the class path, and then run the jar you requested. By default java uses the current directory as the classpath, and when you move to a different folder it can not see where the jars are located.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文