Reputation: 422
I'm trying to execute a Groovy script which is using Microsoft SQL server JDBC driver. I'm trying to specify the path of the sql jdbc jar in the modules directory. However, my groovy script complains that the SQLServerDriver class is not found.
This is what the configuration looks like -
This is the error that I get
Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at groovy.sql.Sql.loadDriver(Sql.java:705)
at groovy.sql.Sql.newInstance(Sql.java:445)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrap.invoke(StaticMetaMethodSite.java:133)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)
at Script1.run(Script1.groovy:23)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:352)
When I print my java classpath in my groovy script I don't see the added module in the classpath either.
println "classPath:" + System.getProperty("java.class.path")
The added URL shows up in the classloader.
Upvotes: 0
Views: 1927
Reputation: 12083
The module won't be in your java.class.path, instead it is added to the classloader. The JAR only needs to be in the system classloader (lib/ folder, e.g.) if you are using DriverManager versus getting an instance of your driver class directly via Class.forName().newInstance().
Perhaps try forward slashes in your path, and if that doesn't work, an experiment could be to try a relative path. If that works, there's a Windows path bug in the processor.
Finally, you could set up a DBCPConnectionPool controller service using the driver JAR and settings, and then access it from your script using the technique I outline in my blog: http://funnifi.blogspot.com/2016/04/sql-in-nifi-with-executescript.html. That way the controller service is reusable by other processors (if need be) and it takes all the guesswork out of setting up the driver, connection, etc.
Upvotes: 0