You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/08/03 23:16:00 UTC

[jira] [Commented] (GROOVY-4895) GroovyShell uses a different class loader than the one that I have specified.

    [ https://issues.apache.org/jira/browse/GROOVY-4895?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16113676#comment-16113676 ] 

Paul King commented on GROOVY-4895:
-----------------------------------

Possibly no longer relevant but did you try using the rootLoader?

> GroovyShell uses a different class loader than the one that I have specified.
> -----------------------------------------------------------------------------
>
>                 Key: GROOVY-4895
>                 URL: https://issues.apache.org/jira/browse/GROOVY-4895
>             Project: Groovy
>          Issue Type: Bug
>         Environment: Generic
>            Reporter: dmantampfl
>
> I have an application in which I am calling a groovy script. The application uses a custom class loader, because I have to load some of jars dynamically, including the jdbc drivers. I am using this class loader in the constructor of GroovyShell(). Here is snippet of my script
> Class.forName("<JDBC driver>");
> connection = DriverManager.getConnection(url,...)
> When I run the script using shell.evaluate(), the driver is registered properly. I know it because, it didn't throw any exception and I have added trace statements in JDK code as well. But when I create the connection it fails with error
> java.sql.SQLException: No suitable driver found for ....
> I listed the registered drivers from DriverManager, it didn't show the jdbc driver I registered earlier. When I debugged the DriverManager, I found that the 'caller' classloader is totally different. It is 'CallSiteClassLoader' which is groovy specific. But the script registered the jdbc driver with the classloader I specified in the groovyShell constructor.
> Groovy should not use its own class loader when I specify a class loader. Or at least it should use my class loader as parent.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)