2

I have an application using Jython 2.1. In the app I was using jythonc to convert the python scripts to java classes and then include these classes in my webapp like any other. So I was able to assign package name to python scripts and access these classes like any other java class.

Now I plan to migrate to Jython 2.5. Jython 2.5 has removed support for jythonc. So I tried to use

jython -m compileall /path/to/my/python/scripts. 

When I do that I get all the compiled bytecode files in the same folder. Each of the files have names like myclass$py.class (where my python file is myclass.py).

My questions -

  1. First of all can I access these classes in another normal java class?
  2. If so, what is the class name I should use ? When I use it like new myclass() my code does not compile.
  3. Is there a way, I can assign / force a package name or class name for the generated bytecode with compileall?

Note -

  • I need to upgrade to jython 2.5 because I need newer versions of python that it supports.
  • I would like to stick with pre-compiling the python code into bytecode, as I want to do optimizations on the bytecode. So the recommended object factory method is only a last resort. I am assuming the object factory approach will not allow me to process the generated bytecode.

Any help is appreciated.

Anupama
  • 167
  • 1
  • 9
  • Can't answer most of your question as I do not use Python, but ... given the generated class name you ***should*** be able to instantiate the Java class as `new myclass().new py();`. – Perception Apr 09 '13 at 05:13
  • @Perception Thanks for your help. Does not look like there exists a true solution to my problem. This [SO Issue](http://stackoverflow.com/questions/2583192/running-jython-bytecode-using-java/15939006#15939006) is the closest I could get to. I took a similar approach to solution, but my python code is much more sophisticated with classes, inheritance et al. So could not get very far. For now I have decided to stick with Jython 2.1 and revisit this later. – Anupama Apr 23 '13 at 04:14
  • @Anupama any luck working on this? If so, please answer your question :) – BoltzmannBrain Mar 24 '15 at 17:29

0 Answers0