From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2af838e78888e2b2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-09 05:58:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.tele.dk!small.news.tele.dk!193.213.112.26!newsfeed1.ulv.nextra.no!nextra.com!news1.oke.nextra.no.POSTED!not-for-mail From: "Frank" Newsgroups: comp.lang.ada References: <3C116B97.9EA057A7@home.com> <3C127350.A502B356@worldnet.att.net> Subject: Re: Java Bindings X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Message-ID: NNTP-Posting-Host: 130.67.137.164 X-Complaints-To: news-abuse@nextra.no NNTP-Posting-Date: Sun, 09 Dec 2001 14:57:59 MET Organization: Nextra Public Access X-Trace: readme.online.no 1007906279 130.67.137.164 Date: Sun, 9 Dec 2001 14:56:53 +0100 Xref: archiver1.google.com comp.lang.ada:17639 Date: 2001-12-09T14:56:53+01:00 List-Id: 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" 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 > /* 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 > > 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