comp.lang.ada
 help / color / mirror / Atom feed
From: James Rogers <jimmaureenrogers@worldnet.att.net>
Subject: Re: Java Bindings
Date: Sat, 08 Dec 2001 20:08:34 GMT
Date: 2001-12-08T20:08:34+00:00	[thread overview]
Message-ID: <3C127350.A502B356@worldnet.att.net> (raw)
In-Reply-To: ug06lvc01.fsf@gsfc.nasa.gov

> 
> 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



  reply	other threads:[~2001-12-08 20:08 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 [this message]
2001-12-09 13:56     ` Frank
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox