Solved

JNI

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 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

14 Experts available now in Live!

Get 1:1 Help Now