Using Jython from the Eclipse Plugin

I find it difficult to work when jython works correctly when launched from the Eclipse plugin. I have a simple factory object that loads a python module corresponding to a Java interface. All this works great offline. However, when I package this as an eclipse plugin, I get another error based on several variables:

Given that my java package is com.foo.

1) If I run without changing any paths, I get: "There is no module named foo"

2) If I then add java jars to sys.path using:

PythonInterpreter interp = new PythonInterpreter(null, new PySystemState()); PySystemState sys = Py.getSystemState(); sys.path.append(new PyString("myjar...")); 

I get:

a) My python module constructor is called (printout is output in constr)
b) I get PySingleton returned from a tojava call. The name field is Error.

3) At this point, I try to make the classpath exactly the same in Eclipse as standalone, so I add my jars to the classpath at runtime just before the python interpreter is called.

I get my favorite error message: SystemError: Automatic proxy initialization should only be performed on proxy classes

This one is driving me crazy. I was impressed with how quickly I got it offline. Should they be running under Eclipse? I believe that this should only be a matter of class, but so far this is not like this.

+2
source share
1 answer

Finally, cross out this. Here is what I had to do:

1) I used the JSR223 ScriptEngine script instead of PythonInterpreter:

engine.get(module_name); //gets the class object of the module getConstructors[0].newInstance(null) on the class to get an object
//cast it to your interface!

2) Make sure your Eclipse plugin is not packaged as a jar (in the 3.5 set of Eclipse-BundleShape: dir)
3) Add jython.jar and any paths in which you want to find the modules in your Runtime Classpath in the manifest.

Hope this helps someone.

+5
source

Source: https://habr.com/ru/post/898153/


All Articles