Python and Java

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JKPeck

    #1

    Python and Java

    Suppose you have an application written in Java, and you want to enable
    other applications or processes written in Python to communicate with
    it, i.e., to use Python as a scripting language for the application.
    On Windows you could do this with COM and various addons such as
    J-Integra and Mark Hammond's libraries.

    How would you do this if you want a mechanism that is portable across
    Windows, Linux, Mac, and Unix?

    Any ideas? Jython would be a natural candidate, but it is stuck at
    Python 2.1 and seems to have an uncertain future.

    Thanks in advance.

  • Paul Rubin

    #2
    Re: Python and Java

    "JKPeck" <JKPeck@gmail.c om> writes:[color=blue]
    > Suppose you have an application written in Java, and you want to enable
    > other applications or processes written in Python to communicate with
    > it, i.e., to use Python as a scripting language for the application.
    > On Windows you could do this with COM and various addons such as
    > J-Integra and Mark Hammond's libraries.
    >
    > How would you do this if you want a mechanism that is portable across
    > Windows, Linux, Mac, and Unix?[/color]

    I suppose you could make some layer that sits between JNI and Python's
    C API. It may be easier to use some slower IPC mechanism like
    sockets, if you can tolerate that.

    Comment

    • Kent Johnson

      #3
      Re: Python and Java

      JKPeck wrote:[color=blue]
      > Suppose you have an application written in Java, and you want to enable
      > other applications or processes written in Python to communicate with
      > it, i.e., to use Python as a scripting language for the application.
      > On Windows you could do this with COM and various addons such as
      > J-Integra and Mark Hammond's libraries.
      >
      > How would you do this if you want a mechanism that is portable across
      > Windows, Linux, Mac, and Unix?
      >
      > Any ideas? Jython would be a natural candidate, but it is stuck at
      > Python 2.1 and seems to have an uncertain future.[/color]

      Jython 2.1 works great and there is (slow) progress being made in
      modernizing it. I recommend it.

      Kent

      Comment

      • Ravi Teja

        #4
        Re: Python and Java

        For most purposes Jython 2.1 is just fine. The lack of recent features
        is not a show stopper. What do you need metaclasses? decorators? BTW,
        there is Jython 2.2 as an alpha release.

        There are a number of ways you can use Java code through Python.

        Use JPype to start a Java VM


        Or compile using GCJ and expose as a DLL/SO or better yet, make a SWIG
        extension.
        A good example for this is PyLucene.
        Python/Java Wrapper Generator

        simplifies the process.

        Or use some standard interop mechanism. Write an XMLRPC/SOAP/CORBA and
        script via Python. This is similar to the COM approach.

        Or maybe, you can look into XPCOM. I have no experience with it.

        And finally a bit more perverse approach that I used once. Converted
        Java bytecode to CIL with IKVM.

        And then I used Python for .NET
        (http://www.zope.org/Members/Brian/PythonNet), a really well
        implemented integration module if I ever saw one, to access the code.

        Comment

        • JKPeck

          #5
          Re: Python and Java

          Thanks for these suggestions. To be clear, we already have a Python
          2.4 minimum requirement for other reasons, and we are looking for a
          long-term solution so that as Python advances, the scripting solution
          can keep up in a timely way.

          Since the Java code is for a very large, complex application, we need
          to bring Python to Java rather than Java to Python.

          We will take a look at some of the other ideas.

          Comment

          • Diez B. Roggisch

            #6
            Re: Python and Java

            JKPeck wrote:
            [color=blue]
            > Suppose you have an application written in Java, and you want to enable
            > other applications or processes written in Python to communicate with
            > it, i.e., to use Python as a scripting language for the application.
            > On Windows you could do this with COM and various addons such as
            > J-Integra and Mark Hammond's libraries.
            >
            > How would you do this if you want a mechanism that is portable across
            > Windows, Linux, Mac, and Unix?
            >
            > Any ideas? Jython would be a natural candidate, but it is stuck at
            > Python 2.1 and seems to have an uncertain future.[/color]

            JPype or CORBA/ICE.

            Diez

            Comment

            • Harry George

              #7
              Re: Python and Java

              "JKPeck" <JKPeck@gmail.c om> writes:
              [color=blue]
              > Suppose you have an application written in Java, and you want to enable
              > other applications or processes written in Python to communicate with
              > it, i.e., to use Python as a scripting language for the application.
              > On Windows you could do this with COM and various addons such as
              > J-Integra and Mark Hammond's libraries.
              >
              > How would you do this if you want a mechanism that is portable across
              > Windows, Linux, Mac, and Unix?
              >
              > Any ideas? Jython would be a natural candidate, but it is stuck at
              > Python 2.1 and seems to have an uncertain future.
              >
              > Thanks in advance.[/color]

              If you need real CPython (e.g., need add-on libraries compiled in C),
              then XMLRPC is a clean way to make the connection.

              Comment

              Working...