groovy script classpath

为君一笑 提交于 2019-11-28 11:27:01
tim_yates

You should be able to do:

import groovy.sql.Sql

@GrabConfig(systemClassLoader=true)
@Grab('mysql:mysql-connector-java:5.1.19')
def getConnection() {
    def dbUrl = 'jdbc:mysql://database1.c5vveqm7rqgx.eu-west-1.rds.amazonaws.com:3306/vouchers_prod'
    def dbUser = 'pucaroot'
    def dbPassword = 'bigsecret'
    def driverClass = "com.mysql.jdbc.Driver"

    return Sql.newInstance(dbUrl, dbUser, dbPassword, driverClass)
}

getConnection().class

Two more options:

  1. Put the jar in ${user.home}/.groovy/lib
  2. If the jar is in a known location, use this code to load it into the current class loader:

    this.class.classLoader.rootLoader.addURL( new URL() )

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!