I want to use some Jython code as a Groovy closure so I believe I need to import the Jython file into the Groovy script and pass it into Groovy's MethodClosure() function to generate the closure.
For example, I put this into a Groovy file:
import rand$py
cl = MethodClosure(rand$py.Rand(), "nextDouble")
Evidently jythonc is deprecated and I couldn't find it on my system so I generated the rand$py.class by importing it from another .py file and running Jython on the other file. The rand$py.class is located in the same directory as the Groovy file.
Here's the error I'm getting when I try to execute the Groovy file:
Exception in thread "main" java.lang.NoClassDefFoundError: org/python/core/PyRunnable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
........
at com.tinkerpop.gremlin.jsr223.ScriptExecutor.evaluate(ScriptExecutor.java:34)
at com.tinkerpop.gremlin.jsr223.ScriptExecutor.main(ScriptExecutor.java:20)
Caused by: java.lang.ClassNotFoundException: org.python.core.PyRunnable
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
It looks like it's finding it because somehow it knows it's a Python file (or does it know that because $py is in them name?). I don't normally work in the JVM so I'm probably missing something fundamental.
EDIT: I changed import rand$py
to import bogus$py
to see if it generated the same error, and it did not so it looks like some part of it is finding the class file:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 80: unable to resolve class bogus$py
@ line 80, column 1.
import bogus$py
^
1 error
I would guess that the Jython libraries are not on your classpath. Look at the classpath section on Groovy Running