views:

123

answers:

2

It looks like I'm missing something.

When using Jython to run my Python code in Java, Java bytecode files are generated (test.py -> [email protected]).

Can I run these classes directly using java?

In other words, I want to make this:

$ java test@py [additional cp args]

work.

The intent: writing Python code and not having to give away source code.

+2  A: 

See FAQ - Embedding Jython.

Note that jythonc is no longer supported:

jythonc doesn't handle generators and is difficult to debug and improve. The current thinking is to add capabilites to jython itself to generate bytecode from py files and run those statically compiled items rather than jythonc's approach of making Java classes that work like the base Python code. The current thinking runs as follows:

  • Turn Python classes into Java classes without a Java interface or class using function annotations to specify the static Java type information
  • statically compile proxy classes for Python classes that extend Java classes
  • remove code from core that is only there to support jythonc

The example suggests special annotation for any method in a Python class that needs to be visible from Java:

class Simple(object):
  @java
  def __init__(self):

  @java(String, String)
  def firstWord(self, param):
    return param.split(' ')[0]
gimel
A: 

If your only concern is distributing your application without giving away the source, you might want to look at tools like cx_freeze and py2exe on Windows and py2app on Mac.

These tools have the ability to compile .py files to bytecode.

Frederik