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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

-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
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
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

-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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.