Article View: borland.public.jbuilder.java.language
Article #18793Re: Java Native Interface problem
From: Lee
Date: Thu, 30 Apr 1998 00:00
Date: Thu, 30 Apr 1998 00:00
95 lines
2805 bytes
2805 bytes
I think you have the wrong declaration in your C code.
It should be like this:
JNIEXPORT void JNICALL Java_MyPackage_HelloWorld_displayHelloWorld
(JNIEnv *, jobject);
You can see the Q&A in Borland's site:
http://www.borland.com/devsupport/jbuilder/qanda/541.html
Cb ���g��峹 <6hkaus$ngc3@forums.borland.com>...
>It seems that Borland has no interest to support JNI?
>
>
>Cb wrote in message <6heahh$hes23@forums.borland.com>...
>>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:
<6i98mm$fhn5@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6heahh$hes23@forums.borland.com> <6hkaus$ngc3@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f74b3,8fa3b4f181a9c1ff X-Google-Attributes: gidf74b3,public From: "Lee" <lhc@iii.org.tw> Subject: Re: Java Native Interface problem Date: 1998/04/30 Message-ID: <6i98mm$fhn5@forums.borland.com> X-Deja-AN: 348994998 References: <6heahh$hes23@forums.borland.com> <6hkaus$ngc3@forums.borland.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language