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.

3
  • 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();. Commented Apr 9, 2013 at 5:13
  • @Perception Thanks for your help. Does not look like there exists a true solution to my problem. This SO Issue 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. Commented Apr 23, 2013 at 4:14
  • @Anupama any luck working on this? If so, please answer your question :) Commented Mar 24, 2015 at 17:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.