native interface

R

romesh

Hi all,
I have c/c++ program that uses a native library(dll/.so) to
perform some task. Is it possible to call the functions of the c/c++
program from java with JNI interface. I just want to wrap the
functions of the c/c++ prgram into a Java API and call them from my
java class.
Thanks in advance.
 
A

Arne Vajhøj

romesh said:
I have c/c++ program that uses a native library(dll/.so) to
perform some task. Is it possible to call the functions of the c/c++
program from java with JNI interface. I just want to wrap the
functions of the c/c++ prgram into a Java API and call them from my
java class.

Java--(JNI)--C/C++ code in .dll/.so--other .dll/.so

should work fine.

Arne
 
I

info

Hi all,
     I have c/c++ program that uses a native library(dll/.so) to
perform some task. Is it possible to call the functions of the c/c++
program from java with JNI interface. I just want to wrap the
functions of the c/c++ prgram into a Java API and call them from my
java class.
Thanks in advance.

Addison-Wesley publishes the definitive JNI reference.. JNI is a bit
too complex to pick up in half an hour of Googling (IMO)
 
T

Tom Anderson

Addison-Wesley publishes the definitive JNI reference.

No, Sun do - it's here:

http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html

There's also a somewhat official book on it, which you can read online
here:

http://java.sun.com/docs/books/jni/html/jniTOC.html
JNI is a bit too complex to pick up in half an hour of Googling (IMO)

Probably true, but JNI really isn't that complex, so i think it's possible
to pick up in an hour or two of reading the docs. I really don't think
there's any need to buy a book.

tom
 
R

Roedy Green

I have c/c++ program that uses a native library(dll/.so) to
perform some task. Is it possible to call the functions of the c/c++
program from java with JNI interface. I just want to wrap the
functions of the c/c++ prgram into a Java API and call them from my
java class.
Thanks in advance.

see http://mindprod.com/jgloss/jni.html
You have to write some glue code, but it can do anything any other C
method can do.
--
Roedy Green Canadian Mind Products
http://mindprod.com
PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
However, he refuses to consider the costs of not implementing Kyoto which the
famous economist Nicholas Stern estimated at 5 to 20% of GDP
 
A

Arved Sandstrom

No, Sun do - it's here:

http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html

There's also a somewhat official book on it, which you can read online
here:

http://java.sun.com/docs/books/jni/html/jniTOC.html


Probably true, but JNI really isn't that complex, so i think it's
possible to pick up in an hour or two of reading the docs. I really
don't think there's any need to buy a book.

tom

JNI itself isn't so bad...not if you're down with C and C++. I've worked
with a few people over the years who came to grief with JNI precisely
because they didn't know C or C++. I'm not suggesting that the OP has
this problem. :)

AHS
 
A

Arne Vajhøj

Tom said:
Probably true, but JNI really isn't that complex, so i think it's
possible to pick up in an hour or two of reading the docs. I really
don't think there's any need to buy a book.

I think it will take a lot more than 1-2 hours to master JNI
with the different data types and memory management
issues.

If the book is good then it may be worth the price.

Arne
 
R

Roedy Green

JNI itself isn't so bad...not if you're down with C and C++. I've worked
with a few people over the years who came to grief with JNI precisely
because they didn't know C or C++. I'm not suggesting that the OP has
this problem. :)

What's missing are a few complete examples. There is plenty of
detailed information, but very little giving you the big picture. I
suggest you example some complete examples, and do the javah, C++
compile and Java compile to put it all together. Once you understand
the example, you have a framework to hang all the detail on.

One fairly simple example to play with is
http://mindprod.com/products1.html#FILETIMES
--
Roedy Green Canadian Mind Products
http://mindprod.com
PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
However, he refuses to consider the costs of not implementing Kyoto which the
famous economist Nicholas Stern estimated at 5 to 20% of GDP
 
T

Tom Anderson

I think it will take a lot more than 1-2 hours to master JNI with the
different data types and memory management issues.

I don't think the data types are at all complicated. Access to object
fields and array elements is a pain, but not conceptually or practically
difficult. The memory management (or rather, reference management - all
that NewGlobalRef stuff) is more of a big deal, but it's actually very
similar to memory management in C - you create a thing, use it, can make
copies of the reference to it, but when you're done, and the last copy is
about to die, you explicitly delete it. It takes the same kind of mental
process to get right. And it's a bloody pain!
If the book is good then it may be worth the price.

I never bought a book, and i can do JNI. I'm by no means a master (there
are whole sets of methods i didn't know about until i was re-reading the
docs just now), but mastery doesn't come from reading books anyway. It's
possible that i'm a genius, or more probably an idiot savant, but i think
it's simply the case that JNI, basic JNI at least, isn't all that hard.

tom
 
R

Roedy Green

I don't think the data types are at all complicated. Access to object
fields and array elements is a pain, but not conceptually or practically
difficul

I once compared it to eating with meter long chopsticks, conceptually
simple but very clumsy.
--
Roedy Green Canadian Mind Products
http://mindprod.com
PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
However, he refuses to consider the costs of not implementing Kyoto which the
famous economist Nicholas Stern estimated at 5 to 20% of GDP
 
T

Tom Anderson

I once compared it to eating with meter long chopsticks, conceptually
simple but very clumsy.

Heh! I'd say more foot-and-a-half-long chopsticks rather than metre. Metre
is more like managing the references. The invocation interface is also
like using metre-long chopsticks - to eat soup.

tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top