我正在编写一个使用 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/