• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

JNI

I have been playing around with the Java Native Interfaces.All of the examples that I have seen have all used javah -jni....then include the created header file inside the C program.  Is there a way to access a C Library and pass stuctures from a java program  without editing a C program. All i have is the ".o".
0
smithc
Asked:
smithc
1 Solution
 
msmolyakCommented:
If I understand you correctly, you need to interface with an existing C library from Java. The only way to do it is to create another shared library which will server as an intermediary between the Java app and the API you are trying to wrap or talk to.

Declaring native methods and then running javah -jni command allows you to generate the signatures of the functions the JVM will call when the native methods will be invoked in your Java program. You have to implement functions with those signatures. Those functions will have a benefit of being able to access the runtime environment and the object or class on which the method was invoked. That function in turn will call an existing C API passing it information from Java program, and then return the rsukts back to Java if necessary. That C function can manipulate Java instance variables on the available objects, call Java methods, create new Java objects andthrow Java exceptions.

I hope this answers your question.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now