1

I am using jython interpreter programmatically (PythonInterpreter) in my java application, and I'd like to add a specific class, eg. MyJythonLib as a Jython import module so that my Jython script could have something like:

import MyJythonLib
a = MyJythonLib.getStuff()

where MyJythonLib.java is

public class MyJythonLib
{
    private Object stuff;
    public Object getStuff()
    {
        return stuff;
    }
}

How do I set this class to be a module for my Jython interpreter?

deckard cain
  • 497
  • 10
  • 24

1 Answers1

0
  1. Ensure MyJythonLib is in your classpath.

  2. import MyJythonLib with reference to its fully qualified name.

For example:

import com.mycompany.MyJythonLib

Or:

from com.mycompany import MyJythonLib

Or:

import com.mycompany.MyJythonLib as MyJythonLib
davidrmcharles
  • 1,923
  • 2
  • 20
  • 33
  • Yeah, I figured Jython searches classpath, but I am not sure how to add the package to classpath. I thought I could somehow search for compiled files during debug session and built application with: `URL package= MyJythonLib.class.getClassLoader().getResource("/");` `URL bundleLocation = FileLocator.resolve(package);` `File file = new File(bundleLocation .toURI());` And then set this path as a search path for modules... Is there any way to do it like this? – deckard cain Jan 22 '18 at 21:25