Groovy 版本:2.0.8
我正在尝试编写一个从私有 Maven 存储库获取 Oracle JDBC 驱动程序的脚本(无需身份验证):
package main.groovy
import groovy.sql.Sql
import java.sql.Connection
import java.sql.DriverManager
@GrabResolver(name='oracle', root='http://my-local-server:8082/maven/repo/')
@Grapes([
@Grab('com.oracle:oracle:11.1.0.7.0'),
@Grab('com.oracle:i18n:10.2.0.5')
])
class FrameworkInspector {
static void main(String[] args) {
//NullPointerException
//this.class.classLoader.getURLs().each{
// ClassLoader.systemClassLoader.addURL(it);
//}
Class.forName("oracle.jdbc.driver.OracleDriver")
java.sql.Connection connection = DriverManager.getConnection(
"jdbc:oracle:thin:@ip:port:sid", "user", "pwd");
Sql sql = new Sql(connection)
println sql.firstRow("select * from dual")
}
}
如何检查我的 jar 是否已加载?目前我得到java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
.