Created
May 1, 2016 23:08
-
-
Save ewized/b8995f7a3f6a09dcf54426d6b6b0ae6b to your computer and use it in GitHub Desktop.
JNI Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "Main.h" | |
using namespace std; | |
// /usr/lib/jvm/java-8-oracle/include/linux | |
JNIEXPORT void JNICALL Java_Main_test__(JNIEnv *env, jobject obj) { | |
cout << env << endl; | |
cout << obj << endl; | |
jclass cls = env->GetObjectClass(obj); | |
cout << cls << endl; | |
} | |
/* | |
* Class: Main | |
* Method: testMain | |
* Signature: ()LMain; | |
*/ | |
JNIEXPORT jobject JNICALL Java_Main_testMain (JNIEnv *env, jobject obj) { | |
return 0; | |
} | |
/* | |
* Class: Main | |
* Method: test | |
* Signature: (I)V | |
*/ | |
JNIEXPORT void JNICALL Java_Main_test__I(JNIEnv *env, jobject obj, jint num) { | |
cout << num << endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <jni.h> | |
#ifndef MAIN_H | |
#define MAIN_H | |
extern "C" { | |
/* | |
* Class: Main | |
* Method: test | |
* Signature: ()V | |
*/ | |
JNIEXPORT void JNICALL Java_Main_test__(JNIEnv *, jobject); | |
/* | |
* Class: Main | |
* Method: testMain | |
* Signature: ()LMain; | |
*/ | |
JNIEXPORT jobject JNICALL Java_Main_testMain(JNIEnv *, jobject); | |
/* | |
* Class: Main | |
* Method: test | |
* Signature: (I)V | |
*/ | |
JNIEXPORT void JNICALL Java_Main_test__I(JNIEnv *, jobject, jint); | |
} | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
private int test = 13; | |
public native void test(); | |
public native Main testMain(); | |
public native void test(int a); | |
public static void main(String[] args) { | |
System.loadLibrary("main"); | |
Main main = new Main(); | |
main.test(); | |
main.test(5); | |
System.out.println(main.testMain()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment