What is the best way to call Java apis from CPython?

Hi,
My CPython client needs to connect and get data from a Java server which returns only Java objects.  There is a Java api to get this data.
What is the best way to call Java apis from CPython and convert the Java objects to CPython objects?

Thanks
Jamie
jamie_lynnAsked:
Who is Participating?
 
-Richard-Commented:
I don't believe so.  Sounds like you're stuck wih CPython.   In which case I think you are also stuck doing it the laborious way.  In broad strokes, what you'd end up doing is this:  

1) Write JNI-aware wrappers in Java for your Java library
2) Write a C++ DLL that wraps the JNI wrapper and presents an API to C-aware applications.
3) Interface to your C++ DLL just like all your other C libraries - I presume you use ctype.

That's the best I can do I'm afraid.   Unless some other expert has a better idea!
0
 
-Richard-Commented:
How firmly commiitted are you to keeping your client as a CPython app?  From Jython this task would be trivial because Jython can natively interface with Java libraries and has built-in mechanisms for converting Java objects to Jython equivalents.   From CPython, II believe it would be challenging and time-consuming.   Quite possibly it would be more challenging and more time-consuming to create the Java interface you desire from CPython than it would be to convert your app to Jython.   The solution would probably involve C++ programming to the JNI (Java Native Interface).  There are people that have already gone this route and written libraries, but they don't look ready-for-prime-time to me.  Here's a link that talks about some of them:  http://wiki.cacr.caltech.edu/danse/index.php/Communication_between_Java_and_Python
I think people pretty much stopped trying to develop this kind of thing once Jython became established.  It's really the ultimate Java/Python solution.
0
 
-Richard-Commented:
Jython link:  http://www.jython.org/
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
jamie_lynnAuthor Commented:
Hi Richard,

I am pretty committed since I have a lot of apis from C libraries that I currently use.
Can Jython call C functions without having a JNI bridge?

Thanks
Jamie
0
 
mish33Commented:
Run Java as a separate process and use RPC to communicate.
0
 
jamie_lynnAuthor Commented:
Hi Mish
That would technically work, but I don't want to do run Java as a separate process... a little too much work and maintenance.  Thanks for the suggestion tho.

Thanks
Jamie
0
 
mish33Commented:
If you want to keep cpython and java it's imho least work.

RPC can be any (from simple shmem and pipes to real xmlrpc or soap).
In my reality rpc takes ~1 day to implement and test (with all libs present).

Otherwise you need to marry two (multithreaded) runtimes which is quite complex.
0
 
-Richard-Commented:
In regards to your previous question, << Can Jython call C functions without having a JNI bridge? >>,  I discovered a "ctypes" implementation for Jython which may allow you to do exactly that:  http://www.fossfactory.org/project/p6?tab=subprojects   I have no experience with this package but it looks like it may do what you want.     Bear in mind that many Python apps can be run as Jython programs without change.  

Sadly, the bottom line is that theris no really easy way to do what you want.  You just have to pick the way that is the least painful!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.