timob / jnigi

Golang Java JNI library
BSD 2-Clause "Simplified" License
166 stars 44 forks source link

Access running JVM #48

Closed cryphrog closed 4 years ago

cryphrog commented 4 years ago

Hey,

first of all i really enjoy working with JNI in Go through your module and wanted to say thanks :) However, I'm working on a project where i have to call functions from a running jvm process, instead of creating a new one. Is this possible with your module? I looked through the source but haven't find anything. Now I'm not sure if this is because I'm new to Go or because this functionality is simply not available. I know this is possible in C++ but since I want to get away from C++ thats not the solution.

Thanks in advance :)

timob commented 4 years ago

Yes you can wrap the JNIEnv * pointer passed to your native function with WrapEnv (https://github.com/timob/jnigi/blob/master/jnigi.go#L95).

With Go you can create shared libraries using go build --buildmode=c-shared. You need export your function using CGo, please read the CGo docs on how to do that.

cryphrog commented 4 years ago

Didn't get managed to get the JNIEnv * pointer. But thats not your problem :D Thanks for the reply, that definitely cleared things up for me.