Search code examples
javagradlejdbcclasspathvertica

Vertica JDBC classes not found after importing locally with gradle


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?


Solution

  • 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.