Integration with java

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

    #1

    Integration with java

    Hello,

    I am working on a project in Python, and I"m
    currently
    looking into the possibiliy of writing some of the
    project"s modules in Java. Given that a large part of
    the code is already written in Python, using the
    standard libraries and several extension modules, I
    am
    trying to gauge the viability of integration with
    Java
    via Jython with minimal impact on present code, on
    the
    complexity of future code, and on deadlines!

    I need to know in general how dirty it will be to
    combine the two languages, and what the costs I
    should
    take into account are. I"m also interested to know if
    there are any commonly accepted strategies to fully
    switch project languages (I"m considering, in the
    extreme case, to change it all into Java), and if
    writing some modules in Java and replacing the rest
    gradually makes sense.

    Three more specific questions I thought of:
    1. Is is possible to pack a Jython/Java program in a
    py2exe-like fashion? Is it possible to pack in such a
    way both Python, Jython and Java code?
    2. Does transferring large data structures between
    Java and Python code running by Jython have a
    significant effect on memory? For example, would
    passing the result of a large database query from
    Java
    to Jython, for further processing, cause the entire
    data to be duplicated or something similar?
    3. Did I miss anything fundemental?

    Thanks!

    Joe.


    _______________ _______________ _______________ _____
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    Yahoo Mail: Your smarter, faster, free email solution. Organize your inbox, protect your privacy, and tackle tasks efficiently with AI-powered features and robust security tools.

  • Istvan Albert

    #2
    Re: Integration with java

    Joachim Boomberschloss wrote:
    [color=blue]
    > the code is already written in Python, using the
    > standard libraries and several extension modules[/color]

    One thing to keep in mind is that Jython does not
    integrate CPython, instead it "understand s" python code
    directly. So if you have a C extension that works with python
    it won't work with Jython.

    My feeling is that if you had a lot of Java code written and
    wanted to build on that with python Jython would be a better
    fit than vice versa.

    Istvan.

    Comment

    • Christopher De Vries

      #3
      Re: Integration with java

      It is possible, though possibly painful, to call java modules from
      CPython using JNI. This is more difficult than Jython integration, but
      probably required if you want to keep using your extension modules.

      The JNI tutorial is available at
      http://java.sun.com/docs/books/tutor...1.1/index.html .

      I probably would not take this approach unless java offered some
      incredibly substantial benefit or I was integrating a complex python
      system with a complex java sytem. I would also probably start by
      creating a good C API to access the required java modules via JNI and
      then use SWIG (http://www.swig.org/) to generate the python wrapper.

      Of course if you can drop the extension modules you have already
      written, accessing Java from Jython is just an import statement away.
      Good luck,

      Chris

      Comment

      • andybak@gmail.com

        #4
        Re: Integration with java

        How about this?


        (I haven't used it myself)

        Comment

        • Cameron Laird

          #5
          Re: Integration with java

          In article <sPSdnWze-4BMcHrcRVn-qA@giganews.com >,
          Istvan Albert <ialbert@mailbl ocks.com> wrote:[color=blue]
          >Joachim Boomberschloss wrote:
          >[color=green]
          >> the code is already written in Python, using the
          >> standard libraries and several extension modules[/color]
          >
          >One thing to keep in mind is that Jython does not
          >integrate CPython, instead it "understand s" python code
          >directly. So if you have a C extension that works with python
          >it won't work with Jython.
          >
          >My feeling is that if you had a lot of Java code written and
          >wanted to build on that with python Jython would be a better
          >fit than vice versa.
          >
          >Istvan.[/color]

          There are other possibilities, though, including JPE
          <URL: http://jpe.sourceforge.net >. I recommend the
          original poster consider the latter.

          Comment

          • Jon Perez

            #6
            Re: Integration with java (Jpype vs. JPE)

            Can someone summarize in a nutshell what is the
            difference between JPype and JPE?

            Comment

            • Cameron Laird

              #7
              Re: Integration with java (Jpype vs. JPE)

              In article <34s5krF4c85d5U 1@individual.ne t>,
              Jon Perez <jbperez808@wah oo.com> wrote:[color=blue]
              >Can someone summarize in a nutshell what is the
              >difference between JPype and JPE?[/color]

              JPE's the original. It provided more functionality than JPype has
              achieved so far, I believe (though that could change any day). I
              think no one now maintains JPE.

              Someone really ought to include a couple of sentences to that effect
              on the front page of <URL: http://jpype.sf.net/ >.

              Comment

              • Steve Menard

                #8
                Re: Integration with java (Jpype vs. JPE)

                Cameron Laird wrote:[color=blue]
                > In article <34s5krF4c85d5U 1@individual.ne t>,
                > Jon Perez <jbperez808@wah oo.com> wrote:
                >[color=green]
                >>Can someone summarize in a nutshell what is the
                >>difference between JPype and JPE?[/color]
                >
                >
                > JPE's the original. It provided more functionality than JPype has
                > achieved so far, I believe (though that could change any day). I
                > think no one now maintains JPE.
                >
                > Someone really ought to include a couple of sentences to that effect
                > on the front page of <URL: http://jpype.sf.net/ >.[/color]

                Well, Cameron summed it up pretty good :)

                I'd add that The only major (and yes I know it is VERY major)
                funtionailty missing in JPype is the ability to subclass Java classes in
                Python.

                On the other hand JPype will (soon) have functionality that JPE doesnt
                have. Java arrays can already (in 0.4) be iterated as regular Python
                collections. Version 0.5 will add that same behavior for Java
                collections (Map, List, Set, Iterator).

                Of course, the above is based on the JPE documentation, because I havent
                been able to get JPE to work.

                About Cameron's suggestion, sure. I'll do it as soon as I (or someone
                else) can get both JPype and JPE to work so they can be compared through
                more than just their respective documentation.

                Steve
                a.k.a devilwolf on sourceforge

                Comment

                • Istvan Albert

                  #9
                  Re: Integration with java (Jpype vs. JPE)

                  Cameron Laird wrote:
                  [color=blue]
                  > Someone really ought to include a couple of sentences to that effect
                  > on the front page of <URL: http://jpype.sf.net/ >.[/color]

                  Now I remember visiting this site, but never understood how it
                  actually worked. Examples such as:

                  from jpype import *
                  startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea")
                  java.lang.Syste m.out.println(" hello world")
                  shutdownJVM()

                  in three different versions are the only code examples
                  that to show "complete" working snippets. I'm still
                  clueless as to how would one say share a list between
                  python and java.

                  Istvan.


                  Comment

                  • Jan Dries

                    #10
                    Re: Integration with java (Jpype vs. JPE)

                    Istvan Albert wrote:[color=blue]
                    > Now I remember visiting this site, but never understood how it
                    > actually worked. Examples such as:
                    >
                    > from jpype import *
                    > startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea")
                    > java.lang.Syste m.out.println(" hello world")
                    > shutdownJVM()
                    >
                    > in three different versions are the only code examples
                    > that to show "complete" working snippets. I'm still
                    > clueless as to how would one say share a list between
                    > python and java.[/color]

                    A while ago there was a thread in c.l.p about using JPype to access JMS
                    from within Python. IIRC someone then contributed a more elaborate real
                    life example of how to do this. Search Google Groups for more details.

                    Regards,
                    Jan

                    Comment

                    • Steve Menard

                      #11
                      Re: Integration with java (Jpype vs. JPE)

                      Istvan Albert wrote:[color=blue]
                      > Cameron Laird wrote:
                      >[color=green]
                      >> Someone really ought to include a couple of sentences to that effect
                      >> on the front page of <URL: http://jpype.sf.net/ >.[/color]
                      >
                      >
                      > Now I remember visiting this site, but never understood how it
                      > actually worked. Examples such as:
                      >
                      > from jpype import *
                      > startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea")
                      > java.lang.Syste m.out.println(" hello world")
                      > shutdownJVM()
                      >
                      > in three different versions are the only code examples
                      > that to show "complete" working snippets. I'm still
                      > clueless as to how would one say share a list between
                      > python and java.
                      >
                      > Istvan.
                      >
                      >[/color]

                      I am sorry you find the site so confusing ... perhpas I shold post a
                      more complete example in a prominent location ...

                      To asnwer your question more fully, the jpype-specific cide is only for
                      looking up the Classes and startting/stopping the environment. For
                      everything else, Java objects and classes are used as regular Python
                      objects.

                      In version 0.4.x, the API mostly remain Java's. This means some of the
                      basic magic python methods have been mapped to java equivalent (like
                      __str__ mapped to toString() and __eq__ mapped to equals()).

                      If you have any questions, feel free to post them on the feedback list
                      on sourceforge. I check it every day and I try to answer as quickly as
                      possible.

                      Steve, aka devilwolf on sourceforge, maintainer of JPype

                      Comment

                      • Dan Bishop

                        #12
                        Re: Integration with java

                        Istvan Albert wrote:[color=blue]
                        > Joachim Boomberschloss wrote:
                        >[color=green]
                        > > the code is already written in Python, using the
                        > > standard libraries and several extension modules[/color]
                        >
                        > One thing to keep in mind is that Jython does not
                        > integrate CPython, instead it "understand s" python code
                        > directly. So if you have a C extension that works with python
                        > it won't work with Jython.[/color]

                        Also, Jython is several versions behind CPython, so any Python code
                        that uses generators or new-style division won't work either.
                        [color=blue]
                        > My feeling is that if you had a lot of Java code written and
                        > wanted to build on that with python Jython would be a better
                        > fit than vice versa.[/color]

                        I agree.

                        Comment

                        • Steve Holden

                          #13
                          Re: Integration with java

                          Dan Bishop wrote:
                          [color=blue]
                          > Istvan Albert wrote:
                          >[color=green]
                          >>Joachim Boomberschloss wrote:
                          >>
                          >>[color=darkred]
                          >>> the code is already written in Python, using the
                          >>> standard libraries and several extension modules[/color]
                          >>
                          >>One thing to keep in mind is that Jython does not
                          >>integrate CPython, instead it "understand s" python code
                          >>directly. So if you have a C extension that works with python
                          >>it won't work with Jython.[/color]
                          >
                          >
                          > Also, Jython is several versions behind CPython, so any Python code
                          > that uses generators or new-style division won't work either.
                          >
                          >[color=green]
                          >>My feeling is that if you had a lot of Java code written and
                          >>wanted to build on that with python Jython would be a better
                          >>fit than vice versa.[/color]
                          >
                          >
                          > I agree.
                          >[/color]
                          Also let's not forget that the PSF has funded a project that's intended
                          to help Jython get up to the curve - see
                          http://www.python.org/psf/grants/Jyt...t_Proposal.pdf. If that
                          project succeeds, and if 2.5 development *does* focus mostly on the
                          library, there's a sporting chance that Jython can be fully up to date
                          for the 2.5 release.

                          regards
                          Steve
                          --
                          Steve Holden http://www.holdenweb.com/
                          Python Web Programming http://pydish.holdenweb.com/
                          Holden Web LLC +1 703 861 4237 +1 800 494 3119

                          Comment

                          • Istvan Albert

                            #14
                            Re: Integration with java (Jpype vs. JPE)

                            Steve Menard wrote:
                            [color=blue]
                            > To asnwer your question more fully, the jpype-specific cide is only for
                            > looking up the Classes and startting/stopping the environment. For
                            > everything else, Java objects and classes are used as regular Python
                            > objects.[/color]

                            Thanks for the response. Currently I don't need to use java but
                            in the past when I explored such a possibility I looked at jpype
                            and I was unable to understand from the documentation what it
                            actually does.

                            There is a lot of text there, but it is all concerning catching
                            errors or other subtleties. For a new visitor the most important
                            question is about how it works, what does it do, and how can it be
                            applied for the given problem.
                            [color=blue]
                            > everything else, Java objects and classes are used as regular Python
                            > objects.[/color]

                            This is too generic. My question was a little more specific,
                            how would I pass a python list as an argument of a java class/method or
                            transform a java list into a python one? You don't have to
                            answer it here, I'm just pointing out the kind of
                            questions that I was unable to get an answer for on the jpype
                            website.

                            best,

                            Istvan.

                            Comment

                            • Steve Menard

                              #15
                              Re: Integration with java (Jpype vs. JPE)

                              Istvan Albert wrote:[color=blue]
                              > Steve Menard wrote:
                              >[color=green]
                              >> To asnwer your question more fully, the jpype-specific cide is only
                              >> for looking up the Classes and startting/stopping the environment. For
                              >> everything else, Java objects and classes are used as regular Python
                              >> objects.[/color]
                              >
                              >
                              > Thanks for the response. Currently I don't need to use java but
                              > in the past when I explored such a possibility I looked at jpype
                              > and I was unable to understand from the documentation what it
                              > actually does.
                              >
                              > There is a lot of text there, but it is all concerning catching
                              > errors or other subtleties. For a new visitor the most important
                              > question is about how it works, what does it do, and how can it be
                              > applied for the given problem.
                              >[color=green]
                              > > everything else, Java objects and classes are used as regular Python
                              > > objects.[/color]
                              >
                              > This is too generic. My question was a little more specific,
                              > how would I pass a python list as an argument of a java class/method or
                              > transform a java list into a python one? You don't have to
                              > answer it here, I'm just pointing out the kind of
                              > questions that I was unable to get an answer for on the jpype
                              > website.
                              >
                              > best,
                              >
                              > Istvan.[/color]

                              I see what you mean. And I agree fully. I guess that's one more thing to
                              put on the TODO list hehe.

                              Thanks for the input.


                              Steve

                              Comment

                              Working...