Solved

JNI

Posted on 1998-11-18
1
344 Views
Last Modified: 2013-11-23
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
Comment
Question by:smithc
1 Comment
 
LVL 5

Accepted Solution

by:
msmolyak earned 100 total points
ID: 1227726
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question