comp.lang.ada
 help / color / mirror / Atom feed
* Java Bindings
@ 2001-12-07 23:16 Bruce or Tracy Jacobs
  2001-12-08 17:48 ` Stephen Leake
  0 siblings, 1 reply; 4+ messages in thread
From: Bruce or Tracy Jacobs @ 2001-12-07 23:16 UTC (permalink / raw)


Just finished a Java class.  Curious as to whether or not anyone has
written a binding so that Ada can talk to Java and pass data.  If so,
what is the URL.  

TIA,
Bruce



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Java Bindings
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Leake @ 2001-12-08 17:48 UTC (permalink / raw)


Bruce or Tracy Jacobs <bljacobs2@home.com> writes:

> Just finished a Java class.  Curious as to whether or not anyone has
> written a binding so that Ada can talk to Java and pass data.  

Since Java is normally interpreted by the JVM, and Ada is normally
compiled to machine code, it is not possible to have a normal binding.

However, there are several options. If you want to write Ada code that
runs on a JVM, and uses all the Sun-defined Java classes, just use an
Ada compiler that targets the JVM (JGNAT or ObjectAda for Java).

There are also utilities that let you call native Ada code from
Java/JVM code.

> If so, what is the URL.

JGNAT: ftp://cs.nyu.edu/pub/gnat/jgnat

ObjectAda: http://www.aonix.com/ (search for "ObjectAda Java")

Native Ada from Java: don't remember, can't find it.

-- 
-- Stephe

PS Hi Bruce :).



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Java Bindings
  2001-12-08 17:48 ` Stephen Leake
@ 2001-12-08 20:08   ` James Rogers
  2001-12-09 13:56     ` Frank
  0 siblings, 1 reply; 4+ messages in thread
From: James Rogers @ 2001-12-08 20:08 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Java Bindings
  2001-12-08 20:08   ` James Rogers
@ 2001-12-09 13:56     ` Frank
  0 siblings, 0 replies; 4+ messages in thread
From: Frank @ 2001-12-09 13:56 UTC (permalink / raw)


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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-12-09 13:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox