From: Diego P. <dgp...@gm...> - 2005-10-05 18:25:25
|
Thx, it worked. Diego 2005/10/5, Bill Woodward <wp...@gm...>: > On 10/3/05, Diego Prestes <dgp...@gm...> 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 < has...@gm...>: > > > > > > 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 <has...@gm...> > > > > > > > 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 Jav= a, > 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 n= ot > overriding methods in the Java base class. Third, it must be in a file w= ith > 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 Jyth= on > 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 fi= le, > something like PluginFunction$_PyInner.class), both contained in the > 'jpywork' subdirectory. These can be imported into a Java program and us= ed > in the normal manner. > > Hope that helps, > - Bill > > -- > Bill Woodward wp...@sa... 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 > |