java - Bat 文件设置类路径

标签 java class batch-file classpath

你能看出下面的代码有什么问题吗?这是一个 bat 文件,我试图在执行我的 jar(jdbc oracle 驱动程序)之前设置一些依赖类。

set CLASSPATH=lib\dbdriver.zip;%CLASSPATH%
java -jar sql2java.jar test.properties
pause

我总是遇到找不到类的异常(该类在我试图添加到类路径中的 zip 中)。 我什至尝试以管理员身份执行此操作,但无济于事

set CLASSPATH=lib\dbdriver.zip;%CLASSPATH%
java -jar %~dp0sql2java.jar %~dp0test.properties
pause

该类位于 zip 文件中(路径\oracle\jdbc\OracleDriver),我正在尝试使用

检索它

jdbc.driver=oracle.jdbc.driver.OracleDriver

最佳答案

检查这个doc关于 java(Java 应用程序启动器)。

对于 -jar 选项,它表示 -

Executes a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. For this option to work, the manifest of the JAR file must contain a line in the form Main-Class: classname. Here, classname identifies the class with the public static void main(String[] args) method that serves as your application's starting point.

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

因此,您要么需要将所有内容打包到您的 jar (sql2java.jar) 中,要么不要将 -jar 选项与 java 一起使用启动器命令。

关于java - Bat 文件设置类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22613705/

相关文章:

C#:如何判断对象是自定义类还是 native 类型/.NET 类?

C++ 类和函数输出问题

java - 如何使用周围方面包装所有存储库调用

java - 如何通过 Java Sockets 使用 IOUtils.copy 传输文件

java - 如何重新启动 Java 小程序?

java - 如何使用java从oracle数据库获取以毫秒为单位的日期/时间?

python - sessionmaker 错误

batch-file - 从批处理中浏览文件夹。我的混合批处理/vbscript

batch-file - 批处理脚本生成特定年月、周和工作日的文件夹

python - Windows 上的 check_call 和命令行参数