使用 gradle 在本地导入后未找到 Vertica JDBC 类

Vertica JDBC classes not found after importing locally with gradle

我一直在尝试使用 gradle 将 Vertica JDBC 添加到我的 java 项目中。由于 vertica JDBC 不在任何回购协议中,我不得不从他们的网站下载它并尝试通过不同的方式将其导入本地:

compile files('lib/vertica-jdbc-10.0.0-0.jar')

implementation files('lib/vertica-jdbc-10.0.0-0.jar')

在本地安装然后正常引用它:

mvn install:install-file "-Dfile=/path_to/vertica-jdbc-10.0.0.jar" "-DgroupId=com.vertica" "-DartifactId=vertica-jdbc" "-Dversion=10.0.0" "-Dpackaging=jar"

然后使用

compile 'com.vertica:vertica-jdbc:10.0.0' / implementation 'com.vertica:vertica-jdbc:10.0.0'

所有这些方法似乎都将它内置到我的 jar 中,如预期的那样在所有文件中找到它在 /com/vertica/ 下。但是,当使用该行时:

Class.forName("com.vertica.jdbc.Driver");

抛出以下异常:

java.lang.ClassNotFoundException: com.vertica.jdbc.Driver
0 = {StackTraceElement@3115} "java.net.URLClassLoader.findClass(URLClassLoader.java:382)"
1 = {StackTraceElement@3116} "java.lang.ClassLoader.loadClass(ClassLoader.java:424)"
2 = {StackTraceElement@3117} "sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)"
3 = {StackTraceElement@3118} "java.lang.ClassLoader.loadClass(ClassLoader.java:357)"
4 = {StackTraceElement@3119} "java.lang.Class.forName0(Native Method)"
5 = {StackTraceElement@3120} "java.lang.Class.forName(Class.java:264)"

关于为什么找不到它的任何想法?我想这是一个类路径问题,但从我读过的内容来看,实现命令应该可以解决这个问题?

原来是我的误会。当尝试 运行 我通过 intellij 这样做的项目时。 Intellij 脱离你的 类,而不是你通过 gradle 构建的任何 jar,所以我需要通过 intellij gui 添加 jar 作为外部依赖。尽管直接调用 jar 时 类 已按预期包含在内。