tags:

views:

1306

answers:

5

I have to integrate a large Java library in a quite large C++ application. A solution is to use JNI but this requires to hand code all the classes. Python has, for example, a wonderful solution with JPype (http://jpype.sourceforge.net/) that automatizes the process (although the same solution cannot be applied to C++ due to C++ and Python different natures).

Thanks,

Das

+3  A: 

SWIG is a tool that lets you auto-generate bindings from one language to another. It supports C++ and Java and a dozen other languages.

sk
I thought that SWIG will create a wrap to make C++ classes available to Java (or any other supported language) and not the other way around (what I need). I will investigate it. Thanks.
dasloop
I may have misunderstood the question then. I don't know if SWIG lets you go in the other direction.
sk
A: 

Not sure if this commercial tool makes life any easier, but you might wanna explore -- http://www.teamdev.com/jniwrapper/index.jsf

anjanb
A: 

JNA is not quite what you're looking for, but it does make your life a lot easier. It doesn't require any boilerplate/generated code - you just write an interface for the methods you want to call.

Certainly, there is every reason to use JNA instead of JNI.

Zarkonnen
A: 

Seems that my question was not clear enough. Maybe the confusion comes from JNI that allows the access in booth directions ...

What I want to do is to access a Java library FROM C++. That is, someone give me a JAR file that contains a collection od JAVA compiled classes and I must write code in C++ to access it (as I want to integrate the functionality of that Java library into a C++ application).

Hope that this clarifies the direction of access :)

Thanks,

Das

dasloop
A: 

I have two suggestions which may or may not work for you:

First, you could try something very simple. Run the Java code in a separate process, and communicate with it with pipes or sockets. This is fairly easy to do, and doesn't require any crazy libraries. The downside is that the communication is somewhat limited (just some simple pipes), you'll need to write your own wrapper around it to send data across

Secondly, what exactly is this library? Perhaps we can suggest alternatives that are not written in Java, that would be much easier to use in your C++ application?

davr