Hello everybody. 
My question is about Jython integration with Groovy.  We have a test automation framework that was written originally in Java but now is incorporating some Groovy for simplicity.  Now we have to integrate with QA team that is using Python in their test automation and we are thinking of using Jython.  I just began on this project and here is the initial problem I encountered:

This Jython code executes with no problem:


import groovy.sql.Sql

sql = groovy.sql.Sql.newInstance("jdbc:postgresql://some_url, "user", "pass", "org.postgresql.Driver");
print (sql.rows("select * from table1"))

However, this Jython code throws a runtime Exception:


import DBConnection


where DBConnection is a Java file with following lines:

import groovy.sql.Sql;

public final class DBConnection
{

    private DBConnection()
    {
       
    }
}

Obviously, there is more code than that but this is enough to illustrate the issue.  The exception is:
java.lang.NoClassDefFoundError: Sql

    at java.lang.Class.getDeclaredMethods0(Native Method)

    at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)

    at java.lang.Class.privateGetPublicMethods(Class.java:2651)

    at java.lang.Class.getMethods(Class.java:1467)

    at org.python.core.PyJavaType.init(PyJavaType.java:273)

    at org.python.core.PyType.createType(PyType.java:1264)

    at org.python.core.PyType.addFromClass(PyType.java:1201)

    at org.python.core.PyType.fromClass(PyType.java:1291)

    at org.python.core.adapter.ClassicPyObjectAdapter$6.adapt(ClassicPyObjectAdapter.java:76)

    at org.python.core.adapter.ExtensiblePyObjectAdapter.adapt(ExtensiblePyObjectAdapter.java:44)

    at org.python.core.adapter.ClassicPyObjectAdapter.adapt(ClassicPyObjectAdapter.java:120)

    at org.python.core.Py.java2py(Py.java:1563)

    at org.python.core.PyJavaPackage.addClass(PyJavaPackage.java:89)

    at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:138)

    at org.python.core.PyObject.__getattr__(PyObject.java:923)

    at org.python.pycode._pyx0.get_testcases$3(C:\ws\git\qa\tests\dataservices\test.py:228)

    at org.python.pycode._pyx0.call_function(C:\ws\git\qa\tests\dataservices\test.py)

    at org.python.core.PyTableCode.call(PyTableCode.java:165)

    at org.python.core.PyBaseCode.call(PyBaseCode.java:120)

    at org.python.core.PyFunction.__call__(PyFunction.java:307)

    at org.python.pycode._pyx0.f$0(C:\ws\git\src\test\java\com\\qa\tests\dataservices\test.py:265)

    at org.python.pycode._pyx0.call_function(C:\ws\git\qa\tests\dataservices\test.py)

    at org.python.core.PyTableCode.call(PyTableCode.java:165)

    at org.python.core.PyCode.call(PyCode.java:18)

    at org.python.core.Py.runCode(Py.java:1275)

    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:235)

    at org.python.util.jython.run(jython.java:247)

    at org.python.util.jython.main(jython.java:129)

Caused by: java.lang.ClassNotFoundException: Sql

    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

    at java.security.AccessController.doPrivileged(Native Method)

    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

    ... 28 more


java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Sql

I'm using Eclipse with PyDev and Jython 2.5.4 .  I'm mixing Java and Jython in the same project.  I think I have all the needed jars in my PYTHONPATH.  So, I observe that importing groovy-sql.jar directly into the Jython code works with no issues, but when the same library is imported by Java class that is imported by itself by some Jython code, something somewhere breaks. 

Any help or advice will be greatly appreciated.


Thanks,
George