This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Crash in JNI test application


Øyvind Harboe wrote:

>My JNI superpowers are rather limited and I haven't tested it against
>Sun's JRE, but the application is simple and is a subset of all the
>JNI helloworld apps out there.
>
Do you really need something so complicated?
Do you have to use the main() in C?

Unless you have some objective that I am missing, you could simply use
a main() in Java!

I would use CNI (unless I was to use the code also with a standard JVM
in which case I would place the C code into a dll and would use JNI).

A CNI example follows (JNI would be almost the same, with changed
function calls and header). The CNI header is created from the
HelloWorld.class by using:
gcjh HelloWorld

To build, please use:
gcj -c HelloWorld.java
gcj -c Hello.cpp
gcj --main=HelloWorld -o HelloWorld.exe HelloWorld.o Hello.o


João



public class HelloWorld {

	public static native void hello();

	public static void main(String[] args) {
		hello();		
	}

}
// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*-

#ifndef __HelloWorld__
#define __HelloWorld__

#pragma interface

#include <java/lang/Object.h>
#include <gcj/array.h>

extern "Java"
{
  class HelloWorld;
}

class HelloWorld : public ::java::lang::Object
{
public:
  HelloWorld ();
  static void hello ();
  static void main (JArray< ::java::lang::String *> *);

  static ::java::lang::Class class$;
};

#endif /* __HelloWorld__ */
#include <stdio.h>
#include <windows.h>
#undef STRICT
#include <gcj/cni.h>
#include "HelloWorld.h"

void HelloWorld::hello () {
  printf("Hello world!");
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]