- 论坛徽章:
- 0
|
源代码如下:
HelloNative.java
class HelloNative
{
static
{
System.loadLibrary("HelloNative");
}
public native static void greeting();
}
HelloNative.h(由javah HelloNative自动产生)
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloNative */
#ifndef _Included_HelloNative
#define _Included_HelloNative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloNative
* Method: greeting
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloNative_greeting
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
HelloNative.c
#include "HelloNative.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_HelloNative_greeting(JNIEnv* env, jclass cl)
{
printf("Hello, Native World!\n");
}
HelloNativeTest.java
class HelloNativeTest
{
public static void main(String args[])
{
HelloNative.greeting();
}
} |
|