Thread: Python and Java

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    3
    Rep Power
    0

    Post Python and Java


    Hi everyone,

    I have been using python for a while now and I want to develop a piece of software in java that call some of my python methods. I have already explored jython however it seems I would have to re-writed the python files however I was wondering if there is anyway in which I can call the python files from java (specifically JBuilder) without doing much changes to the python files.

    Does anyone has any suggestions????


    All help welcomed, thanks.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I havnt done much work with Jython. But i really dont think you will have to rewrite any Python files, that is after all the point of it . Jython should be able to use any Python file/library, or i don't see a reason why not anyway.

    Unfortuantly I havn't heard of any other way of integrating Python with Java, so my best advice would be to give Jython a shot!

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    As netytan said, Jython is designed for this task and most Python scripts should run with little or no modification on Jython. The exception is scripts that use C extensions that have not be converted. Jython is also only at 2.1 at the moment, so 2.2 and later features will not work. A 2.2/2.3 release is supposed to happen later this year.

    There are alternatives though. You could wrap your Python libraries in a wrapper like XML-RPC and run it as a server. Or use a CORBA orb, or SOAP or even COM. These all work in essentially the same way, with the Python running as a separate process and exposing the functionality to client programs that could be written in any language.

    There was also JPI, a CPython <-> Java Interface, but it is no longer being developed and may take some effort to get working with the latest version of Python. You can find it at http://www.ndim.edrc.cmu.edu/dougc/jpi/Home.html.

    Dave - The Developers' Coach
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    I have also found JPE (http://sourceforge.net/projects/jpe) which is similar to JPI, and also no longer being actively developed.

    And SPIRO, a Python -> Java Orb. http://www.freenet.org.nz/python/spiro/

    Dave - The Developers' Coach
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    3
    Rep Power
    0
    Hi,

    thanks for the reply, I installed jython a few weeks ago and then tried to run my python files but there were a number of errors, the way some methods are declared have to be rewritten for them to work.

    Originally Posted by netytan
    I havnt done much work with Jython. But i really dont think you will have to rewrite any Python files, that is after all the point of it . Jython should be able to use any Python file/library, or i don't see a reason why not anyway.

    Unfortuantly I havn't heard of any other way of integrating Python with Java, so my best advice would be to give Jython a shot!

    Mark.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    3
    Rep Power
    0
    Hi,

    thanks for the reply, I thiink I will explore one of your suggestions, I am not too familiar on COM and SOAP but I will research them and give it a try if all else fails then its back to jython. Thanks


    Originally Posted by DevCoach
    As netytan said, Jython is designed for this task and most Python scripts should run with little or no modification on Jython. The exception is scripts that use C extensions that have not be converted. Jython is also only at 2.1 at the moment, so 2.2 and later features will not work. A 2.2/2.3 release is supposed to happen later this year.

    There are alternatives though. You could wrap your Python libraries in a wrapper like XML-RPC and run it as a server. Or use a CORBA orb, or SOAP or even COM. These all work in essentially the same way, with the Python running as a separate process and exposing the functionality to client programs that could be written in any language.

    There was also JPI, a CPython <-> Java Interface, but it is no longer being developed and may take some effort to get working with the latest version of Python. You can find it at http://www.ndim.edrc.cmu.edu/dougc/jpi/Home.html.

    Dave - The Developers' Coach

IMN logo majestic logo threadwatch logo seochat tools logo