Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.6
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:macos 10.5, java 1.6
-
Number of attachments :
Description
The following script fails with a ClassNotFoundException. The script has no problem instantiating the com.mysql.jdbc.Driver class, but groovy.sql.Sql can't do the same. This may be related to GROOVY-3413.
import java.net.URL
import java.net.URLClassLoader
def cp = []
cp << new URL("file:mysql-connector-java-5.1.6-bin.jar")
def loader = new URLClassLoader(cp as URL[], this.class.classLoader)
def shell = new GroovyShell(loader)
def script = """
assert null != new com.mysql.jdbc.Driver()
"""
shell.evaluate(script)
script = """
import groovy.sql.Sql
assert null != Sql.newInstance("jdbc:mysql://localhost:3306/db", "user", "pass", "com.mysql.jdbc.Driver")
"""
shell.evaluate(script)
You can resolve the issue by setting the thread context loader