I think there are some important things to consider first with how strong you wish to have the linking between javaJava and pythonPython.
Firstly Do you only want to call functions or do you actually want pythonPython code to change the data in your java objects? This is very important. If you only want to call some pythonPython code with or without arguments, then that is not very difficult. If your arguments are primitives it makes it even more easy. However, if you want to have javaJava class implement member functions in pythonPython, which change the data of the javaJava object, then this is not so easy or straight forward.
Secondly are we talking cpythonCPython, or will jythonJython do? I would say cpythonCPython is where its at! I would advocate this is why pythonPython is so kool! Having such high abstractions however access to c,c++C or C++ when needed. Imagine if you could have that in javaJava. This question is not even worth asking if jythonJython is ok because then it is easy anyway.
Advantages: Trivially easy. Have actual references to javaJava objects
Jython from javaJava is so easy, and if this is really enough then great. However it is very slow and no cpythonCPython! Is life worth living without cpythonCPython? I don't think so! You can easily have pythonPython code implementing your member functions for you javaJava objects.
Pyro is the remote object module for pythonPython. You have some object on a cpythonCPython interpreter, and you can send it objects which are transferred via serialization and it can also return objects via this method. Note that if you send a serialized pythonPython object from jythonJython and then call some functions which change the data in its members, then you will not see those changes in javaJava. You just need to remember to send back the data which you want from pyroPyro. This, I believe, is the easiest way to get to cpythonCPython! You do not need any jniJNI or jnaJNA or swigSWIG or .... You don't need to know any cC, or c++C++. koolKool huh?
Advantages: Access to cpython, not as difficult as following methods
- Access to CPython
- Not as difficult as following methods
Disadvantages: Cannot change the member data of java objects directly from python. Is somewhat indirect, (jython is middle man).
- Cannot change the member data of Java objects directly from Python
- Is somewhat indirect (Jython is middle man)
OMG this method is not for the faint of heart. And I can tell you it has taken me very long to achieve this in with a decent method. Main reason you would want to do this is so that you can run cpythonCPython code which as full rein over you java object. There are major major major things to consider before deciding to try and bread javabreed Java (which is like a chimp) with pythonPython (which is like a horse). Firstly if you crash the interpreter, that's lights out for you program! And don't get me started on concurrency issues! In addition, there is allot allota lot of boiler, I believe I have found the best configuration to minimize this boiler but still it is allotstill a lot! So how to go about this: Consider that C++ is your middle man, your objects are actually c++C++ objects! Good that you know that now. Just write your object as if your program asis in cppC++ and not javaJava, with the data you want to access from both worlds. Then you can use the wrapper generator called swig (http://www.swig.org/Doc1.3/Java.htmlSWIG) to make this accessible to java and compile a dll which you call System.load(dll name hereSystem.load(dllNameHere)) in javaJava. Get this working first, then move on to the hard part! To get to pythonPython you need to embed an interpreter. Firstly I suggest doing some hello interpreter programs or this tutorial Embedding pythonPython in C/C. Once you have that working, its time to make the horse and the monkey dance! You can send you c++C++ object to pythonPython via [boost][3] . I know I have not given you the fish, merely told you where to find the fish. Some pointers to note for this when compiling.