Article View: borland.public.jbuilder.java.language
Article #18819Java Native Interface problem
From: Cb
Date: Mon, 20 Apr 1998 00:00
Date: Mon, 20 Apr 1998 00:00
72 lines
2116 bytes
2116 bytes
I tried to call Native Method from JBuilder. The example I tried is from
the
famous Java Tutorial book by Mary Campione and Kathy Walrath:
1 Write the Java code
class HelloWorld {
public native void displayHelloWorld();
static {
System.loadLibrary("hello");
}
}
class Main {
public static void main(String[] args) {
new HelloWorld().displayHelloWorld();
}
}
2. Complie the above Java code
3. Create .h file using javah. HelloWorld.h is created:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
4. Write the C code:
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
5. Create DLL using Power++:
Start Power++ using Win32 DLL as the target; add the above C code into a
default project; Build it into HELLO.DLL, HELLO.LIB. In the MAP file, I can
see Java_HelloWorld_displayHelloWorld was exported. Copy the DLL and LIB to
\WINNT\SYSTEM32 directory (I use NT4)
6. Run Main.Class and alwasy get the following error:
java.lang.UnsatisfiedLinkError: displayHelloWorld
at native1.Main.main(Main.java:21)
Your advise will be highly appreciated!
Technical Details
Message-ID:
<6heahh$hes23@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,8fa3b4f181a9c1ff,start X-Google-Attributes: gidf74b3,public From: "Cb" <chens888@cyberway.com.sg> Subject: Java Native Interface problem Date: 1998/04/20 Message-ID: <6heahh$hes23@forums.borland.com> X-Deja-AN: 345809867 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language