Basic polyglot project

This commit is contained in:
2020-10-02 21:57:54 -04:00
commit 91cc4ac60f
11 changed files with 400 additions and 0 deletions

View 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);
}

View 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());
}
}