Java 忽略类路径

标签 java oracle jdbc

我正在编写一个使用 Oracle JDBC 驱动程序的 java 程序。我已将其设置在我的类路径中。当我在 IDE 中运行程序(作为 jdbc 添加为库)时,程序运行良好。当我尝试部署它时,它完全忽略类路径中的列表并给我一个 NoClassDefFoundError。

我想使用客户端的 JDBC 驱动程序(已安装的驱动程序)并且不提供我自己的驱动程序。我从 JDeveloper 打包程序,部署为 JAR 文件。

运行方式:java -jar test.jar

当我将库放入 %JAVA_HOME%/lib/ext 时,它可以正常工作。

有人知道如何解决这个问题吗?

最佳答案

当您使用 java -jar 运行时,类路径将被忽略。

您需要使用Class-Path list 属性。

来自http://download.oracle.com/javase/tutorial/deployment/jar/downman.html

You specify classes to include in the Class-Path header field in the manifest file of an applet or application. The Class-Path header takes the following form:

Class-Path: jar1-name jar2-name directory-name/jar3-name

来自http://download.oracle.com/javase/1.4.2/docs/tooldocs/linux/java.html

-jar

...

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

关于Java 忽略类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61292531/

相关文章:

java - 过滤查询以获取包含常量后跟特殊字符的字符串?

java - 异常启动前的MySQL

java - ORA-12514 : TNS:listener does not currently know of service requested in connect descriptor

java - 如何运行位于远程服务器上的jar

java - 从 Worklight 适配器调用 Java 类的 ECMA TypeError

java - Hibernate 映射可选值

java - java聊天Socket连接数

c# - 参数定界符

sql - select 中的 if 语句 (ORACLE)

java - 使用 hibernate 连接到数据库 - 连接 url