On 10/3/05, Diego Prestes <dgprestes@gmail.com> wrote:
> I don't know if you dont understand me or I don't understand what you
> said, ehe. What I want is create a java program and that program calls
> this code that jythonc converts. This classpath that you said is put
> the jython.jar file in the classpath?
> thx,
> Diego
> 2005/10/3, Hasan Diwan < hasan.diwan@gmail.com>:
> >
> > On Sep 30, 2005, at 3:01 PM, Diego Prestes wrote:
> >
> > > class PluginFunction:
> > >     def execute( self ):
> > >         print "HelloWorld"
> > >
> > > Someone can help me saying how can I call this in Java?
> >
> > Compile using jythonc PluginFunction.py and run using the classpath
> > the jython compiler gives you. It works here.
> >
> > Cheers,
> > Hasan Diwan <hasan.diwan@gmail.com>
> >

I'll translate :)  Actually, he was pretty clear, if a bit terse.  The jythonc compiler is a tool to convert a Jython file into a Java class.  There are a few restrictions on the Jython class for it to compile to Java, though.  First, your Jython class must inherit from a Java base class.  Second, it needs to have some @sig doc strings for any methods that are not overriding methods in the Java base class.  Third, it must be in a file with the same name as the Jython class (just like Java files need to have the same name as the public Java class they contain).

All of this is from memory, but I've been re-reading "Jython for Java Programmers", and it has a good section on compiling from Jython to Java.  It also only covers Jython 2.1, so it may be somewhat different with Jython 2.2 (currently in alpha).

So try this:

--- begin PluginFunction.py ---
class PluginFunction(java.lang.Object):
    def execute( self ):
        "@sig public void execute()"
        print "HelloWorld"
--- end PluginFunction.py ---

And then compile with 'jythonc PluginFunction.py'.  If everything goes right, you should get a Java PluginFunction.class (plus an inner class file, something like PluginFunction$_PyInner.class), both contained in the 'jpywork' subdirectory.  These can be imported into a Java program and used in the normal manner.

Hope that helps,
- Bill

Bill Woodward     wpwood@saifa.net      http://www.saifa.net

"I have more trouble with D. L. Moody than with any other man I ever met." -- D. L. Moody
        s/D. L. Moody/Bill Woodward/g