From: "Frank" <franjoe@frisurf.no>
Subject: Re: Java Bindings
Date: Sun, 9 Dec 2001 14:56:53 +0100
Date: 2001-12-09T14:56:53+01:00 [thread overview]
Message-ID: <H5KQ7.11114$yB2.177401@news1.oke.nextra.no> (raw)
In-Reply-To: 3C127350.A502B356@worldnet.att.net
Hi!
I believe it would be a good idea to put this issue + these answers in the
Ada FAQ at http://www.adapower.com
Frank
"James Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
news:3C127350.A502B356@worldnet.att.net...
> >
> > Native Ada from Java: don't remember, can't find it.
> >
>
> Following the JNI (Java Native Interface) rules, you would need to
> create a C program as a wrapper to call the Ada library. The C
> wrapper must be compiled as a DLL (WIN32) or Shared Object (Unix,
> Linux).
>
> The C wrapper must include the C header file generated by the
> javah program based upon the Java "wrapper" class defining the Java
> view of the method(s) to be called.
>
> The Java view of interfacing to other languages is that the other
> language must perform all the conversions to Java. Java remains
> ignorant of other language issues. For instance, there is NO Java
> equivalent to Ada's Convention parameter to the Ada Import
> statement.
>
> A simple example just between C and Java:
>
> 1) Create the Java "wrapper" class:
>
> public class Thing
> {
> public native void displayThing();
> static
> {
> System.loadLibrary("thing");
> }
> }
>
> 2) Run "javah Thing" to generate the appropriate C header file:
> The resulting header file follows:
>
> /* DO NOT EDIT THIS FILE - it is machine generated */
> #include <jni.h>
> /* Header for class Thing */
>
> #ifndef _Included_Thing
> #define _Included_Thing
> #ifdef __cplusplus
> extern "C" {
> #endif
> /*
> * Class: Thing
> * Method: displayThing
> * Signature: ()V
> */
> JNIEXPORT void JNICALL Java_Thing_displayThing
> (JNIEnv *, jobject);
>
> #ifdef __cplusplus
> }
> #endif
> #endif
>
> 3) Create the C implementation of the method(s) defined in the Java
> "wrapper" class:
>
> #include "Thing.h"
> #include <stdio.h>
>
> JNIEXPORT void JNICALL Java_Thing_displayThing
> (JNIEnv *, jobject)
> {
> printf("This is the thing\n");
> return;
> }
>
> 4) Compile the C code to a shared object or dll
> You also need to put the resulting C library file in a directory
> named in the PATH variable in NT or the LD_LIBRARY_PATH in
> Unix.
>
> 5) Create a Java program to instantiate the wrapper class and call the
> native method.
>
> Jim Rogers
> Colorado Springs, Colorado USA
prev parent reply other threads:[~2001-12-09 13:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-07 23:16 Java Bindings Bruce or Tracy Jacobs
2001-12-08 17:48 ` Stephen Leake
2001-12-08 20:08 ` James Rogers
2001-12-09 13:56 ` Frank [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox