Solved

JNI

Posted on 1998-11-18
1
339 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now