How java communicate with c++ (experts please take a look)

I encounter problems in my new project.

My client uses websphere as their app server and put ejb on it. They are now trying to introduce an image server on another machine to deal with image processing function. The image server provides some visual c++ lib calls and functions for programmer to work for, but it doesn't support java. So my client now asking me to write some java package for the websphere which hidden all c++'s works and call the image server to work(the 2 servers is distributed).

I start investigation from JNI at first. however, I found that JNI needs customizes the C++ code and of course i won't have it. So I give up this. Then, I start thinking to put a layer on the C++, and then use JNI to deal with this c++ layer. These steps I think should be on image server. So the next step is use RMI or Corba to communicate the websphere and image server, right?

I dont know whether this can be work or not, but I feel its to complex. I then think whether I can directly access the c++ file on the image server if I just know the image server's dll or function. I even dont know whether the image server have COM or support corba...

Can expertists give me some suggestions or reference!?

Thx a lots!!

[1268 byte] By [denniswty] at [2007-9-26 14:18:05]
# 1

>>I found that JNI needs customizes the C++ code and of course i won't have it

This is not correct, you do not need to touch the c/c++ code that is already there. What happens is you create a wrapper function in c/c++ that calls your c/c++ functions. You build your c/c++ wrapper function and create either a .dll or .so file, depending on what platform you are on. You then use a system.loadlibrary in java to so that you can call the c/c++ function from java.

derekcameron at 2007-7-2 15:52:56 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2

ooh, thx! I understand what u mean. Write a C++ layer which includes the funciton of the dll. And then use this c++ layer works with JNI. That's the way to use existing dll without modification... But I seems really a tedious and terrible works if there is hundred or thousand of these dll functions..

Btw, can I use COM or Corba to deal with? I heard corba can exchange data for different programming language especially for OO.

denniswty at 2007-7-2 15:52:56 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

So many topics.

Someone has suggested 'swig' in the past. (That is not the same as swing). It produces a interface layer (java) from another layer (like C++.) The url is http://www.swig.org/.

You need to provide a communication layer. You can either use RMI or sockets. I wouldn't suggest corba unless you are already familar with it and have a server.

JNI use C as the inteface layer not C++. You can use the standard tricks to use C++. The JNI javah stuff already supports this as it supplies macros which resolve to extern "C" declarations. If that doesn't mean anything to you then just ignore it. But keep in mind that C++ methods can NOT be used as native methods, although they can be used by those methods.

jschell at 2007-7-2 15:52:56 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4
Thanks jschell. Very detailed information and clarify my mistakes. I now know how the architecture of it.
denniswty at 2007-7-2 15:52:56 > top of Java-index,Archived Forums,New To Java Technology Archive...