How do I load the Oracle driver from the local file system?

(Dean Schulze) #1

How do I load the Oracle driver from the local file system? This should be simple, but gradle is turning this into a multi-hour task.

The following doesn’t work because it doesn’t know find the ojdbc-14.jar file in the lib/ directory:

repositories {

flatDir name: ‘localRepository’, dirs: ‘lib’ }

configurations {

driver }

task loadOracle() << {

URLClassLoader loader = GroovyObject.class.classLoader

configurations.driver.each {File file ->


println file.toURL()


//Class driverClass = loader.loadClass(‘oracle.jdbc.OracleDriver’)


java.sql.Driver driverInstance = driverClass.newInstance()



Sql sql = Sql.newInstance(‘jdbc-url’,‘username’,‘password’) }

(x1000) #2

It should be like this

buildscript {
  dependencies {
    classpath files('lib/ojdbc-14.jar')

(Peter Niederwieser) #3

See my answer on Stack Overflow. Please don’t double-post.

(x1000) #4

The example code looked like he wanted to use the sql driver from within the build script (didn’t mentioned that it was for jetty)…

(chanun) #5

Could be an alternative.

With this line, it works for me.

dependencies {
 runtimeWithoutCompile fileTree(dir: 'lib', include: '*.jar')