Using Python Classes from Java without Factories / Jython on Java ME

View: New views
2 Messages — Rating Filter:   Alert me  

Using Python Classes from Java without Factories / Jython on Java ME

by Jan Wedel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi,

 

I’m currently looking for a way to get a python script running on an Java ME (IMP/CLDC) environment. I actually already ported PyMite to Java but it was to slow because it was interpreting Python byte code at runtime.

 

Then I though Clamp could be the solution and Charlie Groves pointed me back to jython which is able to compile Python scripts to class files.

 

I used the compileall script to compile a midlet written in python, something like this:

from javax.microedition.midlet import MIDlet

class PyMidlet(MIDlet):

                def __init__(self):

                               print "Midlet Constructor"         

                def startApp(self):

                               print "Application started."                       

                def pauseApp(self):

                               print "Application paused."                       

                def destroyApp(self, cond):

                               print "Application destroyed, condition=", cond

 

I packaged this as a jar, created a jad and run it with the WTK emulator. It says not Midlet “PyMidlet” found. Then I used JBE to look at the generated java bytecode and compared it to the bytecode of a “real” Java midlet.

 

Taking a quick look, I saw two important things:

1.)    It implements the PyRunnable interface instead of MIDlet

2.)    All method got a $1, $2 attached to its names.

 

So, now the question, is it possible, to create a class file that looks and behaves like a “real” MIDlet from other java classes?

 

Ok, and the second, maybe more important, question is, is “only” the python libraries implemented in Java that use advanced java features (HashMap e.g.)  that do not exist in JavaME? That would be Ok, because I’m a pro in porting JavaSE code to JavaME. Or, does the core part, that is essentially necessary to run even the most simple python script, does use e.g. class loading which can not be implemented in Java ME at all?

 

What I need is a self-contained jar file including only the necessary class files. I don’t need the interpreter and features like the interactive input.

 

So, I am willing to spend some time (days, weeks) to the necessary work to get it running on Java ME. But if there is some general restrictions in the architecture of Jython, it won’t be possible.

 

Any comments are welcome!

 

Jan


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users

Re: Using Python Classes from Java without Factories / Jython on Java ME

by Alex Grönholm-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jan Wedel kirjoitti:

>
> Hi,
>
>  
>
> I’m currently looking for a way to get a python script running on an
> Java ME (IMP/CLDC) environment. I actually already ported PyMite to
> Java but it was to slow because it was interpreting Python byte code
> at runtime.
>
>  
>
> Then I though Clamp could be the solution and Charlie Groves pointed
> me back to jython which is able to compile Python scripts to class files.
>
>  
>
> I used the compileall script to compile a midlet written in python,
> something like this:
>
> from javax.microedition.midlet import MIDlet
>
> class PyMidlet(MIDlet):
>
>                 def __init__(self):
>
>                                print "Midlet Constructor"        
>
>                 def startApp(self):
>
>                                print "Application
> started."                      
>
>                 def pauseApp(self):
>
>                                print "Application
> paused."                      
>
>                 def destroyApp(self, cond):
>
>                                print "Application destroyed,
> condition=", cond
>
>  
>
> I packaged this as a jar, created a jad and run it with the WTK
> emulator. It says not Midlet “PyMidlet” found. Then I used JBE to look
> at the generated java bytecode and compared it to the bytecode of a
> “real” Java midlet.
>
>  
>
> Taking a quick look, I saw two important things:
>
> 1.)    It implements the PyRunnable interface instead of MIDlet
>
> 2.)    All method got a $1, $2 attached to its names.
>
>  
>
> So, now the question, is it possible, to create a class file that
> looks and behaves like a “real” MIDlet from other java classes?
>
>  
>
> Ok, and the second, maybe more important, question is, is “only” the
> python libraries implemented in Java that use advanced java features
> (HashMap e.g.)  that do not exist in JavaME? That would be Ok, because
> I’m a pro in porting JavaSE code to JavaME. Or, does the core part,
> that is essentially necessary to run even the most simple python
> script, does use e.g. class loading which can not be implemented in
> Java ME at all?
>
>  
>
> What I need is a self-contained jar file including only the necessary
> class files. I don’t need the interpreter and features like the
> interactive input.
>
>  
>
> So, I am willing to spend some time (days, weeks) to the necessary
> work to get it running on Java ME. But if there is some general
> restrictions in the architecture of Jython, it won’t be possible.
>
This is exactly what Clamp is meant to do. Charlie Groves has not yet
finished his work on the necessary proxy generation hooks in Jython,
which would enable Clamp to function. If you want to expedite the
process, offer him your help.

>
>  
>
> Any comments are welcome!
>
>  
>
> Jan
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> ------------------------------------------------------------------------
>
> _______________________________________________
> Jython-users mailing list
> Jython-users@...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>  


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users