.class file from jython with pydev

My first jython attempt is a java / jython project which I am writing in eclipse with pydev.

I created a java project and then made the pydev project RightClick project β†’ pydev β†’ installed as ... you got the idea. Then I added two source folders: one for java and one for jython, and there is a package in each source folder. And I set each folder as the build path for the project. I assume that I will let you know all this, so I hope you can tell me that I am sure that the project was set up correctly.

But the real question is: how can I get jython code in a class file so that Java code can use it? . The preferred method would be that eclipse / pydev would do this for me automatically, but I cannot figure it out. Something mentioned in the jython user guide implies that this is possible, but I cannot find information about it anywhere.

EDIT: I found some information here and here , but things are not going too smoothly.

I followed the guide carefully in the second link, but I cannot figure out how to get jythonc to create a constructor for my python class.

+3
java python eclipse jython pydev
Jul 02 '09 at 18:17
source share
2 answers

Jythonc no longer exists, it was dropped into another project called Clamp , but with that said ...

... you can precompile your python scripts for .class files with:

jython [jython home] /Lib/compileall.py [the directory where you store the python code]

Source - Jython Newsletter March 2009

When I gave him the folder with the Python 2.7 code (knowing that this would not work in Jython 2.5 ), he returned a .class file, although it is not a function. Try this with your Jython scripts. If this works, let us know, because I will be where you are soon.

Once you are so far away, it’s easy to convert the command line operator to an external tool in PyDev, which can be called as needed.

+5
Jul 08 '10 at 18:35
source share
β€” -

After the tutorial "Accessing Jython from Java without using jythonc", it became possible to use jython modules inside java code. The only tricky point is that * .py modules are not compiled into * .class files. So this turns out to be an exotic script inside java. Performance may, of course, degrade vs jythonc'ed py modules, but as I got on the jython community pages, they are not going to support jythonc (and actually already dumped it in jython2.5.1).

So, if you decide to follow the non-jythonc approach, the above tutorial is perfect. I had to slightly modify the JythonFactory.java code:

String objectDef = "=" + javaClassName + "(your_constructor_params here)"; try { Class JavaInterface = Class.forName(interfaceName); System.out.println("JavaInterface=" + JavaInterface); javaInt = interpreter.get("instance name of a jython class from jython main function").__tojava__(JavaInterface); } catch (ClassNotFoundException ex) { ex.printStackTrace(); // Add logging here } 
0
Oct 14 '09 at 0:29
source share



All Articles