Vertica JDBC类在使用Gradle本地导入后找不到

huangapple go评论68阅读模式
英文:

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)"

你有关于为什么无法找到它的任何想法吗?我想这可能是一个类路径问题,但根据我阅读的内容,implementation命令应该可以解决这个问题?

英文:

i've been trying to add the vertica JDBC to my java project using gradle. As the vertica JDBC is not on any repos, I've had to download it from their site and try to import it locally through different means:

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

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

Installing it locally and then referencing it as normal:

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"

then using

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

All of these methods do seem to get it built into my jar, finding it under /com/vertica/ as expected with all the files. However when using the line:

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

The following exception gets thrown:

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)"

Any ideas as to why it cannot be found? i imagine it is a classpath problem but from what i've read the implementation command is suppose to take care of this?

答案1

得分: 0

原来是我的误解。在尝试运行项目时,我是通过Intellij来运行的。Intellij使用的是您的类,而不是通过gradle构建的任何jar包,所以我需要通过Intellij图形界面将该jar包添加为外部依赖。尽管直接调用jar包时,类被如预期般地包含进来。

英文:

Turns out a misunderstanding on my part. When attempting to run the project I was doing so through intellij. Intellij off of your classes, not any jars you've built through gradle and so i needed to add the jar as an external dependency through intellij gui. Although when calling the jar directly the classes are included as expected.

huangapple
  • 本文由 发表于 2020年9月4日 20:22:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63741109.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定