mirror of
https://github.com/speice-io/polyglot_jni
synced 2025-07-03 15:14:41 -04:00
Basic polyglot project
This commit is contained in:
13
src/main/c/io/speice/Polyglot.c
Normal file
13
src/main/c/io/speice/Polyglot.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include "io_speice_Polyglot.h"
|
||||
|
||||
const char message[] = "Hello, world!";
|
||||
|
||||
/*
|
||||
* Class: io_speice_Polyglot
|
||||
* Method: getMessage
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_io_speice_Polyglot_getMessage(JNIEnv *env, jclass class) {
|
||||
|
||||
return (*env)->NewStringUTF(env, message);
|
||||
}
|
27
src/main/java/io/speice/Polyglot.java
Normal file
27
src/main/java/io/speice/Polyglot.java
Normal file
@ -0,0 +1,27 @@
|
||||
package io.speice;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Polyglot {
|
||||
|
||||
static {
|
||||
// Because CMake will process this file to generate native headers, we can't
|
||||
// import NativeLoader directly (CMake won't have it on the compile path when
|
||||
// calling javac).
|
||||
// Instead, use reflection to find it. Because this is only run once, the cost
|
||||
// of reflection is negligible.
|
||||
try {
|
||||
Class<?> c = Class.forName("org.scijava.nativelib.NativeLoader");
|
||||
Method m = c.getDeclaredMethod("loadLibrary", String.class, String[].class);
|
||||
m.invoke(null, "polyglot", null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static native String getMessage();
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Polyglot.getMessage());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user