0

I have some libraries written in Groovy. I'd like to know if I can use them in python (jython). (By using I mean importing and instantiating them like normal java classes)

First I thought I could since groovy compiles down to .class files but then I got this exception

Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject
at org.python.core.SyspathJavaLoader.findClass(SyspathJavaLoader.java:128)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 40 more

I was getting this even after I put the groovy jars on the classpath.

This is the command I am running:

jython -Dpython.path=<absolute path to groovy compiled classfiles>:<user home>.gradle/caches:<user home>.sdkman/candidates/groovy/current/lib test.py

(where current groovy version is 2.5.7)

test.py

from my.library.api import AGroovyClass
print("working")

In this particular case I just wanted to make sure I can at least import it. Is it possible to do this?

c_maker
  • 19,076
  • 1
  • 24
  • 29
  • 1
    Which groovy jars did you put on the classpath? – tim_yates Jan 25 '20 at 09:31
  • @tim_yates I guess I lied. I put the jars on python.path based on this article: https://wiki.python.org/jython/LearningJython#classpath-and-python-path and this post: https://stackoverflow.com/questions/537682/how-can-i-add-jars-to-the-classpath-when-i-invoke-jython-without-adding-them-t – c_maker Jan 25 '20 at 16:15
  • 1
    The jars will need to be on the classpath, so the JVM running jython can find them – tim_yates Jan 25 '20 at 17:13
  • @tim_yates makes sense. Will give it a try and report back. – c_maker Jan 25 '20 at 19:41

0 Answers0