Code Monkey home page Code Monkey logo

jnigi's Introduction

JNIGI

JNI Go Interface.

A package to access Java from Go code. Can be used from a Go executable or shared library. This allows for Go to initiate the JVM or Java to start a Go runtime respectively.

Go Reference Actions

Module name change

The go module name is renamed to github.com/timob/jnigi in the branch. Checkout v2 if you want to retain the old name.

Install

# In your apps Go module directory
go get github.com/timob/jnigi

# Add flags needed to include JNI header files, change this as appropriate for your JDK and OS
export CGO_CFLAGS="-I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux"

# build your app
go build

The compilevars.sh (compilevars.bat on Windows) script can help setting the CGO_CFLAGS environment variable.

Finding JVM at Runtime

The JVM library is dynamically linked at run time. Use the LoadJVMLib(jvmLibPath string) error function to load the shared library at run time. There is a function AttemptToFindJVMLibPath() string to help to find the library path.

Status

Testing

Most of the code has tests. To run the tests using docker:

# get source
git clone https://github.com/timob/jnigi.git

cd jnigi

# build image
docker build -t jnigi_test .

# run tests
docker run jnigi_test

Uses

Has been used on Linux/Windows/MacOS (amd64) Android (arm64) multi threaded apps.

Note about using on Windows

Because of the way the JVM triggers OS exceptions during CreateJavaVM, which the Go runtime treats as unhandled exceptions, the code for the Go runtime needs to be changed to allow the JVM to handle the exceptions. See #31 (comment) for how to do this.

Example

package main

import (
    "fmt"
    "github.com/timob/jnigi"
    "log"
    "runtime"
)

func main() {
    if err := jnigi.LoadJVMLib(jnigi.AttemptToFindJVMLibPath()); err != nil {
        log.Fatal(err)
    }

    runtime.LockOSThread()
    jvm, env, err := jnigi.CreateJVM(jnigi.NewJVMInitArgs(false, true, jnigi.DEFAULT_VERSION, []string{"-Xcheck:jni"}))
    if err != nil {
        log.Fatal(err)
    }

    hello, err := env.NewObject("java/lang/String", []byte("Hello "))
    if err != nil {
        log.Fatal(err)
    }

    world, err := env.NewObject("java/lang/String", []byte("World!"))
    if err != nil {
        log.Fatal(err)
    }

    greeting := jnigi.NewObjectRef("java/lang/String")
    err = hello.CallMethod(env, "concat", greeting, world)
    if err != nil {
        log.Fatal(err)
    }

    var goGreeting []byte
    err = greeting.CallMethod(env, "getBytes", &goGreeting)
    if err != nil {
        log.Fatal(err)
    }

    // Prints "Hello World!"
    fmt.Printf("%s\n", goGreeting)

    if err := jvm.Destroy(); err != nil {
        log.Fatal(err)
    }
}

jnigi's People

Contributors

andrewmostello avatar aniket144 avatar dawndiy avatar dbarganski avatar edisoncxr avatar hscells avatar iamcalledrob avatar jairobjunior avatar linguofeng avatar mlaggner avatar timob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jnigi's Issues

[macosx] "No Java runtime present, requesting install" when creating VM from JNI

As described in java JDK-7131356

On some Mac OS machines, if one tries to create Java VM from native executable using JNI, they will get "No Java runtime present, requesting install." message and the program will simply exit. In graphical session, there will be a popup "To open JavaApplication, you need a Java runtime. Would you like to install one now?" "Not now" "Install".

Workaround here:
https://github.com/openjdk/jdk/blob/a20c31865d82a71c946d93da30a1e7e8b2970273/test/hotspot/gtest/gtestMain.cpp#L226

Further evidence here:
s-u/rJava#37 (comment)

My dirty code fix confirmed to solve the bug (w/o error handling and resource free)

// preload libjli
	libname := filepath.Dir(jvmLibPath)+"/../jli/libjli.dylib"
	u := C.CString(libname)
	handle := C.dlopen((*C.char)(u), C.RTLD_NOW|C.RTLD_GLOBAL)
//load jvm
	jnigi.LoadJVMLib(config.jvmLibPath)

Android support

I'm exploring adding Android support to this library, and have a few questions/thoughts.

Initialization

Context: There are two ways to get a reference to the JVM in Android, depending on how the process is set up.

  1. If the process is a "native" binary built with the NDK, you can spin up the JVM with JNI_CreateJavaVM from libart.so
  2. If the process is an Android JVM app then the Go code must be being used as a library—in which case, JNI_OnLoad will be called with the corresponding JVM/Env. It's not possible to use JNI_CreateJavaVM

The initialization patterns of this library currently map 1:1 to (1) above. I could easily create an android.go implementation that implements LoadJVMLib and jni_CreateJavaVM. But I imagine most people will want to use this in scenario (2)—where their Go code is acting as a shared library.

I'm curious how to think about initialization for scenario (2). My current idea would be to implement LoadJVMLib and jni_CreateJavaVM, which would plug into the existing code.

Then have a new higher level constructor, e.g. FindOrCreateJVM() which either calls CreateJVM or creates a new *JVM, *Env pair from the JVM provided by the host environment if JNI_OnLoad was invoked by the JVM already. This would probably need to be paired with changes to Destroy() so that it only does so if the JVM was actually created by us.

Constants

JNI_VERSION_1_8 = C.JNI_VERSION_1_8

This causes a compile failure when building with the Android NDK, which only supports up to JNI_VERSION_1_6. It would be possible to shim this so that JNI_VERSION_1_8 exists in C-land, though you wouldn't actually be able to use it.

--

In theory, this should be all it takes to get this working on Android too. Curious if you have any thoughts/advice?

Support converting int32 return values

See #62 (comment)

Right now we convert return int values but not int32.

I think we should probably do int -> Int , int32 -> Int and int <- Int, int32 <- Int.

But with int -> Int on 64 bit systems if the int value is greater than max Int value return an error.

Unable to Instantiate Multiple JVMs for jnigo

Hi Tim,

main.txt
In the attached file I have a requirement to instantiate multiple JVMs. The code I am running in order to do that is attached.
I am basically calling thee loadJVm and create JVM multiple times in a for loop but I get an error
Hello World!2020/09/28 18:36:44 Couldn't instantiate JVM
exit status 1
It was able to create load and create the JVM for the first time but not in the second time. Can you please help on how to fix it?
Below os the main.go code
Please help.
Thanks
package main

import (
"fmt"
"github.com/timob/jnigi"
"log"
)

func main() {

// can access using struct now
// fmt.Println("dll : ", conf.Dll);
// fmt.Println("classpath : ", conf.Classpath);
// fmt.Println("classname : ", conf.Classname);
//if err := jnigi.LoadJVMLib("/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre/lib/server/libjvm.dylib"); err != nil {
//t := time.Now()
for i := 0; i < 2; i++ {
if err := jnigi.LoadJVMLib("/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre/lib/server/libjvm.dylib"); err != nil {
    log.Fatal(err)
}
jvm, env, err := jnigi.CreateJVM(jnigi.NewJVMInitArgs(false, true, jnigi.DEFAULT_VERSION, []string{"-Xcheck:jni"}))
if err != nil {
    log.Fatal(err)
}

hello, err := env.NewObject("java/lang/String", []byte("Hello "))
if err != nil {
    log.Fatal(err)
}

world, err := env.NewObject("java/lang/String", []byte("World!"))
if err != nil {
    log.Fatal(err)
}

v, err := hello.CallMethod(env, "concat", jnigi.ObjectType("java/lang/String"), world)
if err != nil {
    log.Fatal(err)
}
greeting := v.(*jnigi.ObjectRef)

v, err = greeting.CallMethod(env, "getBytes", jnigi.Byte|jnigi.Array)
if err != nil {
    log.Fatal(err)
}
goGreeting := string(v.([]byte))

// Prints "Hello World!"
fmt.Printf("%s", goGreeting)

if err := jvm.Destroy(); err != nil {
    log.Fatal(err)
}

}
//os.Exit(130)
}

could not dynamically load libjvm.so

Hi ,

I followed all the steps mentioned in README file i.e

  1. setting up CGO_CFLAGS

Here are platform details
Platform : Ubuntu 22.04.1 LTS
JDK Path : /usr/lib/jvm/java-17-amazon-corretto

But still its throwing could not dynamically load libjvm.so. Can you please help me

signal arrived during external code execution

Hi. Can you help with the problem。

Exception 0xc0000005 0x0 0x0 0x177800003b6
PC=0x177800003b6
signal arrived during external code execution

runtime.cgocall(0xbd638d, 0xc000121ab8)
        C:/Software/gosdk/go1.17.6/src/runtime/cgocall.go:156 +0x4a fp=0xc000121a80 sp=0xc000121a48 pc=0xb0434a
demo/jnigi._Cfunc_dyn_JNI_CreateJavaVM(0x177d5695630, 0x177d5694980, 0x177d5692840)
        _cgo_gotypes.go:2876 +0x5a fp=0xc000121ab8 sp=0xc000121a80 pc=0xbc867a
demo/jnigi.jni_CreateJavaVM.func1(0x177d5695630, 0x177d5694980, 0x177d5692840)
        D:/workspace/workspace_go/jnigi_demo/src/demo/jnigi/windows.go:43 +0xc5 fp=0xc000121b20 sp=0xc000121ab8 pc=0xbce9e5
demo/jnigi.jni_CreateJavaVM(0x177d5695630, 0x177d5694980, 0x177d5692840)
        D:/workspace/workspace_go/jnigi_demo/src/demo/jnigi/windows.go:43 +0x3f fp=0xc000121b50 sp=0xc000121b20 pc=0xbce8df
demo/jnigi.CreateJVM(0xc000006030)
        D:/workspace/workspace_go/jnigi_demo/src/demo/jnigi/jnigi.go:171 +0x85 fp=0xc000121bf0 sp=0xc000121b50 pc=0xbb7aa5
main.main()
        D:/workspace/workspace_go/jnigi_demo/src/demo/main.go:19 +0x205 fp=0xc000121f80 sp=0xc000121bf0 pc=0xbcf865
runtime.main()
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:255 +0x1d7 fp=0xc000121fe0 sp=0xc000121f80 pc=0xb3a537
runtime.goexit()
        C:/Software/gosdk/go1.17.6/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000121fe8 sp=0xc000121fe0 pc=0xb626c1

goroutine 2 [force gc (idle)]:
runtime.gopark(0xc19b00, 0xca0ca0, 0x11, 0x14, 0x1)
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:366 +0xf2 fp=0xc000057f88 sp=0xc000057f58 pc=0xb3a932
runtime.goparkunlock(0x0, 0x0, 0x0, 0x0)
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:372 +0x2a fp=0xc000057fb8 sp=0xc000057f88 pc=0xb3a9ca
runtime.forcegchelper()
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:306 +0xa5 fp=0xc000057fe0 sp=0xc000057fb8 pc=0xb3a765
runtime.goexit()
        C:/Software/gosdk/go1.17.6/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000057fe8 sp=0xc000057fe0 pc=0xb626c1
created by runtime.init.7
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:294 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0xc19b00, 0xca0da0, 0xc, 0x14, 0x1)
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:366 +0xf2 fp=0xc000059f88 sp=0xc000059f58 pc=0xb3a932
runtime.goparkunlock(0x0, 0x0, 0x0, 0x0)
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:372 +0x2a fp=0xc000059fb8 sp=0xc000059f88 pc=0xb3a9ca
runtime.bgsweep()
        C:/Software/gosdk/go1.17.6/src/runtime/mgcsweep.go:163 +0x8f fp=0xc000059fe0 sp=0xc000059fb8 pc=0xb23d6f
runtime.goexit()
        C:/Software/gosdk/go1.17.6/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000059fe8 sp=0xc000059fe0 pc=0xb626c1
created by runtime.gcenable
        C:/Software/gosdk/go1.17.6/src/runtime/mgc.go:181 +0x55

goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc19b00, 0xca0e00, 0xd, 0x14, 0x1)
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:366 +0xf2 fp=0xc000069f58 sp=0xc000069f28 pc=0xb3a932
runtime.goparkunlock(0x0, 0x0, 0x0, 0x0)
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:372 +0x2a fp=0xc000069f88 sp=0xc000069f58 pc=0xb3a9ca
runtime.bgscavenge()
        C:/Software/gosdk/go1.17.6/src/runtime/mgcscavenge.go:265 +0xd4 fp=0xc000069fe0 sp=0xc000069f88 pc=0xb21cf4
runtime.goexit()
        C:/Software/gosdk/go1.17.6/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000069fe8 sp=0xc000069fe0 pc=0xb626c1
created by runtime.gcenable
        C:/Software/gosdk/go1.17.6/src/runtime/mgc.go:182 +0x65

goroutine 5 [finalizer wait]:
runtime.gopark(0xc19b00, 0xcf6ad8, 0x10, 0x14, 0x1)
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:366 +0xf2 fp=0xc00005be00 sp=0xc00005bdd0 pc=0xb3a932
runtime.goparkunlock(0xc000054ea0, 0x80, 0x11, 0xc00005bf70)
        C:/Software/gosdk/go1.17.6/src/runtime/proc.go:372 +0x2a fp=0xc00005be30 sp=0xc00005be00 pc=0xb3a9ca
runtime.runfinq()
        C:/Software/gosdk/go1.17.6/src/runtime/mfinal.go:177 +0xab fp=0xc00005bfe0 sp=0xc00005be30 pc=0xb19f2b
runtime.goexit()
        C:/Software/gosdk/go1.17.6/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc00005bfe8 sp=0xc00005bfe0 pc=0xb626c1
created by runtime.createfing
        C:/Software/gosdk/go1.17.6/src/runtime/mfinal.go:157 +0x45
rax     0x6
rbx     0xa100800
rcx     0xcafebabe
rdi     0x1
rsi     0x0
rbp     0x6572e4a0
rsp     0x6b4c5ff468
r8      0x1778000047b
r9      0x6b4c5ff630
r10     0x2
r11     0x6b4c5ff7a0
r12     0x3d8
r13     0x0
r14     0xc000054000
r15     0x20
rip     0x177800003b6
rflags  0x210246
cs      0x33
fs      0x53
gs      0x2b

go version
go version go1.16.4 windows/amd64

java version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

Access running JVM

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 :)

cgo runtime error No space left on device

sometimes when concurrent execution too much times, cgo will throw a crash ,i use LD_PRELOAD set SA_ONSTACK flag get the reason.
runtime/cgo: pthread_create failed: No space left on device
i think the resource is enough, anyone have encounter this issue, thanks!

Fix support for Windows

The current master doesn't support Windows anymore because the functions:

jni_GetDefaultJavaVMInitArgs
jni_CreateJavaVM

are not implemented in windows.go. Please see linux.go for how these are implemented. Basically this file dynamically loads the jvm library.

Redesign API

For the next version. I think that the CallMethod/Field methods currently on ObjectRef which take an Env as a paramter should be methods of Env rather thant ObjectRef.

This is so that state, like errors for example can be tracked in the Env struct. This would allow for:

hashCode := env.CallMethod(obj, "hashCode", jnigi.Int).(int)
if env.ErrorOccurred() != nil {
   // deal with error
}
// use hashCode

Make loading JVM a package function

Re: 4a6d124#r33728275
There has been some discussion on what is the best practice to load the JVM at runtime, i think we can probably make it not JNIGI's problem and just provide a function:

func LoadJVM(jvmSharedLibraryPath string) error

This will replace the current init() function, then the program using JNIGI can decide how it wants to find the library.

how to pass go func to jvm

Hi I wanted to ask how it is possible to pass a go func as an implementation to an object in JVM that implements the java.util.function.Function<String,String> interface.

Is there a way and if yes, what steps do I need for that?

I have tried the following attempt:

fn_obj, err := env.NewObject("java/util/function/Function", nil)
fn_obj.SetField(env, "apply", func() {})

This of course fails, because there is no <init> ctor for an interface. My goal is to provide an implementation in go for that interface.

signal arrived during external code execution

hi!
when i run example code in windows, get this

Exception 0xc0000005 0x0 0x0 0x3a903b6
PC=0x3a903b6
signal arrived during external code execution

github.com/timob/jnigi._Cfunc_dyn_JNI_CreateJavaVM(0x6b7f90, 0x6b7f70, 0x7a7f90, 0x0)
        _cgo_gotypes.go:2691 +0x54
github.com/timob/jnigi.jni_CreateJavaVM.func1(0x6b7f90, 0x6b7f70, 0x7a7f90, 0x519040)
        github.com/timob/jnigi/windows.go:42 +0xcb
github.com/timob/jnigi.jni_CreateJavaVM(0x6b7f90, 0x6b7f70, 0x7a7f90, 0xc000092030)
        github.com/timob/jnigi/windows.go:42 +0x46
github.com/timob/jnigi.CreateJVM(0xc000092030, 0x10006, 0xc00008ff20, 0x1, 0x1)
        github.com/timob/jnigi/jnigi.go:97 +0x7b
rax     0x6
rbx     0x4200800
rcx     0xcafebabe
rdi     0x1
rsi     0x0
rbp     0x511e9020
rsp     0x22f578
r8      0x3a9047b
r9      0x22f740
r10     0x2
r11     0x22f8b0
r12     0x3d8
r13     0x7
r14     0x6
r15     0x400
rip     0x3a903b6
rflags  0x210246
cs      0x33
fs      0x53
gs      0x2b
gosdk : go1.13.4
jdk : 
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

Loading JVM from a path containing unicode characters

I saw that loading the JVM from a path containing an unicode character (e.g. Séries) fails. If I change the path name to use only ASCII character, loading succeeds.

As far as I found out, the Windows API LoadLibrary has two different flavours which are used on compile time: LoadLibraryA (ASCII variant - default) and LoadLibraryW (unicode variant).

After researching for a few more hours I say that I need to set a compiler variable tho force the usage of the unicode variant which I did via (windows.go):

/*
#include <jni.h>

// we need to compile with unicode support on Windows
#ifndef UNICODE
#define UNICODE
#endif

#ifndef _UNICODE
#define _UNICODE
#endif

#include <windows.h>

which leads to some compiler errors. After fiddling a bit more with the parameters for LoadLibrary (which does not accept a C.char in the unicode variant) I got it compiling again, but the result did not work either.

Did I miss anything else or am I simply wrong?

Is it possible to do that for android?

Hope it can do that for android so that we can write android app mostly in golang while some can be done in calling java, such as setup service.

Thanks

macOS AWT/Swing support

I am just trying to use this lib in my golang launcher for my Java Swing application. I managed to start up the JVM and load the first few lines of code before the EventDispatchThread starts. My Java program looks like

public static void main(String[] args) {
  // do something before EDT
  EventQueue.invokeLater(new Runnable() {
    public void run() {
      // start the UI-application
    }
  }
}

In the logs of the application I just see the lines before the EDT start but afterwards nothing happens and the launcher is just "hung".

I found the issues #35 and the PR #36 and #43 but I did not find the right solution for the problem. According to the example of OpenJDK (https://github.com/AdoptOpenJDK/openjdk-jdk/blob/master/src/java.base/macosx/native/libjli/java_md_macosx.m#L354) I see that we need to rund main in a new thread and "park" the first thread - OpenJDK uses CoreFoundation here...

Is this still needed for using this lib? Why has the corresponding code been removed from PR #43?

I have a full setup to help here, but my knowledge with CGO is very limited (I am a Java developer :) ).

Unable to install

Hi,

I got this error when trying to install this library:

image

Any help will be appreciated.
Thanks

fatal error: jni.h: No such file or directory


ubuntu@ip-172-31-54-208:~/go$ java -version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-3)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
ubuntu@ip-172-31-54-208:~/go$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial
ubuntu@ip-172-31-54-208:~/go$ go get github.com/timob/jnigi
# github.com/timob/jnigi
src/github.com/timob/jnigi/cinit.go:8:16: fatal error: jni.h: No such file or directory
compilation terminated.

FATAL ERROR in native method: Using JNIEnv in non-Java thread

Hi,

If I initialize JVM (load, create, etc.) in the main function, I can successfully execute a Java code without any problems. However, If I try to initialize JVM only once after the application has started instead of initializing for each call and call a Java code in handler functions, I get the following error:

FATAL ERROR in native method: Using JNIEnv in non-Java thread

Could you please help with what I am trying to achieve? Basically, I want to create an end-point in a Go application which will call some Java code each time request is received.

The sample code I am working with is here TinkJNIGo

callMethod is not work for complex function

assume this function:
public com.google.gson.JsonArray test(String input){
}
obj.CallMethod(env, "test", jnigi.ObjectType("com/google/gson/JsonArray"),"java/lang/String", test_str);

but callMethod can not generate the right function signature.it can't distinct test_str is parameter or actual parameter, maybe i incorrectly use of the function.

New `CallMethod` does not seem to base the call on a casted object ref

I have a simple class hierarchy in my project, e.g., ObjectType which derives from Type. ObjectType has a function addGeneric which takes a Type as parameter and returns void.

I am trying to cast-call this method on an object ref, but it seems that the base class is chosen for the method call, rather than the casted class:

t.Cast("de/fraunhofer/aisec/cpg/graph/types/ObjectType").CallMethod(env, "addGeneric", nil, g.Cast("de/fraunhofer/aisec/cpg/graph/types/Type"))
java.lang.NoSuchMethodError: Lde/fraunhofer/aisec/cpg/graph/types/Type;.addGeneric(Lde/fraunhofer/aisec/cpg/graph/types/Type;)V

Not able to find java class even after loading classpath

Hi,
we tried using the jnigi to connect java to go but even when we load the classpath, it still says class not found.
project structure:

project:
    |
    ---- main.go
    |
    |
    ---- go.mod
    |
    |
    ---- go.sum
    |
    |
    ---- abc2.jar

main.go

package main

import (
	"log"
	"runtime"

	"github.com/timob/jnigi"
)

func main() {
	if err := jnigi.LoadJVMLib("/opt/homebrew/Cellar/openjdk@21/21.0.3/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib"); err != nil {
		log.Fatal(err)
	}

	runtime.LockOSThread()
	_, env, err := jnigi.CreateJVM(jnigi.NewJVMInitArgs(false, true, jnigi.DEFAULT_VERSION, []string{"-Xcheck:jni", "-Xbootclasspath/a:./abc2.jar", "-verbose:class"}))
	if err != nil {
		log.Fatal(err)
	}
	cls, err := env.FindClass("com.person.Person")
	if err != nil {
		log.Fatalf("class not found, err: %v", err)
	}
	log.Println("found class", cls)
}

abc2.jar is a simple java project fat jar file which has a class com.person.Person.
The ouput I am getting:

# command-line-arguments
ld: warning: '/private/var/folders/60/nq6yrbkx0flf1t4jn1qdg6vr0000gq/T/go-link-2269234384/go.o' has malformed LC_DYSYMTAB, expected 53 undefined symbols to start at index 3319, found 75 undefined symbols starting at index 15
[0.033s][info][class,load] opened: ./abc2.jar
[0.078s][info][class,load] java.lang.Object source: shared objects file
[0.079s][info][class,load] java.io.Serializable source: shared objects file
[0.079s][info][class,load] java.lang.Comparable source: shared objects file
[0.079s][info][class,load] java.lang.CharSequence source: shared objects file
[0.079s][info][class,load] java.lang.constant.Constable source: shared objects file
[0.079s][info][class,load] java.lang.constant.ConstantDesc source: shared objects file
[0.079s][info][class,load] java.lang.String source: shared objects file
[0.079s][info][class,load] java.lang.reflect.AnnotatedElement source: shared objects file
[0.079s][info][class,load] java.lang.reflect.GenericDeclaration source: shared objects file
[0.079s][info][class,load] java.lang.reflect.Type source: shared objects file
[0.079s][info][class,load] java.lang.invoke.TypeDescriptor source: shared objects file
[0.079s][info][class,load] java.lang.invoke.TypeDescriptor$OfField source: shared objects file
[0.079s][info][class,load] java.lang.Class source: shared objects file
[0.079s][info][class,load] java.lang.Cloneable source: shared objects file
[0.079s][info][class,load] java.lang.ClassLoader source: shared objects file
[0.079s][info][class,load] java.lang.System source: shared objects file
[0.079s][info][class,load] java.lang.Throwable source: shared objects file
[0.079s][info][class,load] java.lang.Error source: shared objects file
[0.079s][info][class,load] java.lang.Exception source: shared objects file
[0.079s][info][class,load] java.lang.RuntimeException source: shared objects file
[0.079s][info][class,load] java.lang.SecurityManager source: shared objects file
[0.079s][info][class,load] java.security.ProtectionDomain source: shared objects file
[0.079s][info][class,load] java.security.AccessControlContext source: shared objects file
[0.079s][info][class,load] java.security.AccessController source: shared objects file
[0.079s][info][class,load] java.security.SecureClassLoader source: shared objects file
[0.079s][info][class,load] java.lang.ReflectiveOperationException source: shared objects file
[0.079s][info][class,load] java.lang.ClassNotFoundException source: shared objects file
[0.079s][info][class,load] java.lang.Record source: shared objects file
[0.079s][info][class,load] java.lang.LinkageError source: shared objects file
[0.079s][info][class,load] java.lang.NoClassDefFoundError source: shared objects file
[0.079s][info][class,load] java.lang.ClassCastException source: shared objects file
[0.079s][info][class,load] java.lang.ArrayStoreException source: shared objects file
[0.079s][info][class,load] java.lang.VirtualMachineError source: shared objects file
[0.079s][info][class,load] java.lang.InternalError source: shared objects file
[0.079s][info][class,load] java.lang.OutOfMemoryError source: shared objects file
[0.079s][info][class,load] java.lang.StackOverflowError source: shared objects file
[0.079s][info][class,load] java.lang.IllegalMonitorStateException source: shared objects file
[0.079s][info][class,load] java.lang.ref.Reference source: shared objects file
[0.079s][info][class,load] java.lang.ref.SoftReference source: shared objects file
[0.079s][info][class,load] java.lang.ref.WeakReference source: shared objects file
[0.079s][info][class,load] java.lang.ref.FinalReference source: shared objects file
[0.079s][info][class,load] java.lang.ref.PhantomReference source: shared objects file
[0.079s][info][class,load] java.lang.ref.Finalizer source: shared objects file
[0.079s][info][class,load] java.lang.Runnable source: shared objects file
[0.079s][info][class,load] java.lang.Thread source: shared objects file
[0.079s][info][class,load] java.lang.Thread$FieldHolder source: shared objects file
[0.079s][info][class,load] java.lang.Thread$Constants source: shared objects file
[0.079s][info][class,load] java.lang.Thread$UncaughtExceptionHandler source: shared objects file
[0.079s][info][class,load] java.lang.ThreadGroup source: shared objects file
[0.079s][info][class,load] java.lang.BaseVirtualThread source: shared objects file
[0.079s][info][class,load] java.lang.VirtualThread source: shared objects file
[0.079s][info][class,load] java.lang.ThreadBuilders$BoundVirtualThread source: shared objects file
[0.080s][info][class,load] java.util.Dictionary source: shared objects file
[0.080s][info][class,load] java.util.Map source: shared objects file
[0.080s][info][class,load] java.util.Hashtable source: shared objects file
[0.080s][info][class,load] java.util.Properties source: shared objects file
[0.080s][info][class,load] java.lang.Module source: shared objects file
[0.080s][info][class,load] java.lang.reflect.AccessibleObject source: shared objects file
[0.080s][info][class,load] java.lang.reflect.Member source: shared objects file
[0.080s][info][class,load] java.lang.reflect.Field source: shared objects file
[0.080s][info][class,load] java.lang.reflect.Parameter source: shared objects file
[0.080s][info][class,load] java.lang.reflect.Executable source: shared objects file
[0.080s][info][class,load] java.lang.reflect.Method source: shared objects file
[0.080s][info][class,load] java.lang.reflect.Constructor source: shared objects file
[0.080s][info][class,load] jdk.internal.vm.ContinuationScope source: shared objects file
[0.080s][info][class,load] jdk.internal.vm.Continuation source: shared objects file
[0.080s][info][class,load] jdk.internal.vm.StackChunk source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.MagicAccessorImpl source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.MethodAccessor source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.MethodAccessorImpl source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.ConstructorAccessor source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.ConstructorAccessorImpl source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.DelegatingClassLoader source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.ConstantPool source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.FieldAccessor source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.FieldAccessorImpl source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.UnsafeFieldAccessorImpl source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.UnsafeStaticFieldAccessorImpl source: shared objects file
[0.080s][info][class,load] java.lang.annotation.Annotation source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.CallerSensitive source: shared objects file
[0.080s][info][class,load] jdk.internal.reflect.NativeConstructorAccessorImpl source: shared objects file
[0.080s][info][class,load] java.lang.invoke.MethodHandle source: shared objects file
[0.080s][info][class,load] java.lang.invoke.DirectMethodHandle source: shared objects file
[0.080s][info][class,load] java.lang.invoke.VarHandle source: shared objects file
[0.080s][info][class,load] java.lang.invoke.MemberName source: shared objects file
[0.080s][info][class,load] java.lang.invoke.ResolvedMethodName source: shared objects file
[0.080s][info][class,load] java.lang.invoke.MethodHandleNatives source: shared objects file
[0.080s][info][class,load] java.lang.invoke.LambdaForm source: shared objects file
[0.080s][info][class,load] java.lang.invoke.TypeDescriptor$OfMethod source: shared objects file
[0.080s][info][class,load] java.lang.invoke.MethodType source: shared objects file
[0.080s][info][class,load] java.lang.BootstrapMethodError source: shared objects file
[0.080s][info][class,load] java.lang.invoke.CallSite source: shared objects file
[0.080s][info][class,load] jdk.internal.foreign.abi.NativeEntryPoint source: shared objects file
[0.080s][info][class,load] jdk.internal.foreign.abi.ABIDescriptor source: shared objects file
[0.080s][info][class,load] jdk.internal.foreign.abi.VMStorage source: shared objects file
[0.080s][info][class,load] jdk.internal.foreign.abi.UpcallLinker$CallRegs source: shared objects file
[0.080s][info][class,load] java.lang.invoke.MethodHandleNatives$CallSiteContext source: shared objects file
[0.080s][info][class,load] java.lang.invoke.ConstantCallSite source: shared objects file
[0.080s][info][class,load] java.lang.invoke.MutableCallSite source: shared objects file
[0.080s][info][class,load] java.lang.invoke.VolatileCallSite source: shared objects file
[0.080s][info][class,load] java.lang.AssertionStatusDirectives source: shared objects file
[0.080s][info][class,load] java.lang.Appendable source: shared objects file
[0.080s][info][class,load] java.lang.AbstractStringBuilder source: shared objects file
[0.080s][info][class,load] java.lang.StringBuffer source: shared objects file
[0.080s][info][class,load] java.lang.StringBuilder source: shared objects file
[0.080s][info][class,load] jdk.internal.misc.UnsafeConstants source: shared objects file
[0.080s][info][class,load] jdk.internal.misc.Unsafe source: shared objects file
[0.080s][info][class,load] jdk.internal.module.Modules source: shared objects file
[0.080s][info][class,load] java.lang.AutoCloseable source: shared objects file
[0.080s][info][class,load] java.io.Closeable source: shared objects file
[0.080s][info][class,load] java.io.InputStream source: shared objects file
[0.080s][info][class,load] java.io.ByteArrayInputStream source: shared objects file
[0.080s][info][class,load] java.net.URL source: shared objects file
[0.080s][info][class,load] java.net.URLClassLoader source: shared objects file
[0.080s][info][class,load] java.lang.Enum source: shared objects file
[0.080s][info][class,load] java.util.jar.Manifest source: shared objects file
[0.080s][info][class,load] jdk.internal.loader.BuiltinClassLoader source: shared objects file
[0.080s][info][class,load] jdk.internal.loader.ClassLoaders source: shared objects file
[0.080s][info][class,load] jdk.internal.loader.ClassLoaders$AppClassLoader source: shared objects file
[0.080s][info][class,load] jdk.internal.loader.ClassLoaders$PlatformClassLoader source: shared objects file
[0.080s][info][class,load] java.security.CodeSource source: shared objects file
[0.080s][info][class,load] java.util.AbstractMap source: shared objects file
[0.080s][info][class,load] java.util.concurrent.ConcurrentMap source: shared objects file
[0.080s][info][class,load] java.util.concurrent.ConcurrentHashMap source: shared objects file
[0.081s][info][class,load] java.lang.Iterable source: shared objects file
[0.081s][info][class,load] java.util.Collection source: shared objects file
[0.081s][info][class,load] java.util.AbstractCollection source: shared objects file
[0.081s][info][class,load] java.util.SequencedCollection source: shared objects file
[0.081s][info][class,load] java.util.List source: shared objects file
[0.081s][info][class,load] java.util.AbstractList source: shared objects file
[0.081s][info][class,load] java.util.RandomAccess source: shared objects file
[0.081s][info][class,load] java.util.ArrayList source: shared objects file
[0.081s][info][class,load] java.lang.StackTraceElement source: shared objects file
[0.081s][info][class,load] java.nio.Buffer source: shared objects file
[0.081s][info][class,load] java.lang.StackWalker source: shared objects file
[0.081s][info][class,load] java.lang.StackStreamFactory$AbstractStackWalker source: shared objects file
[0.081s][info][class,load] java.lang.StackWalker$StackFrame source: shared objects file
[0.081s][info][class,load] java.lang.StackFrameInfo source: shared objects file
[0.081s][info][class,load] java.lang.LiveStackFrame source: shared objects file
[0.081s][info][class,load] java.lang.LiveStackFrameInfo source: shared objects file
[0.081s][info][class,load] java.util.concurrent.locks.AbstractOwnableSynchronizer source: shared objects file
[0.081s][info][class,load] java.lang.Boolean source: shared objects file
[0.081s][info][class,load] java.lang.Character source: shared objects file
[0.081s][info][class,load] java.lang.Number source: shared objects file
[0.081s][info][class,load] java.lang.Float source: shared objects file
[0.081s][info][class,load] java.lang.Double source: shared objects file
[0.081s][info][class,load] java.lang.Byte source: shared objects file
[0.081s][info][class,load] java.lang.Short source: shared objects file
[0.081s][info][class,load] java.lang.Integer source: shared objects file
[0.081s][info][class,load] java.lang.Long source: shared objects file
[0.081s][info][class,load] java.util.Iterator source: shared objects file
[0.081s][info][class,load] java.lang.reflect.RecordComponent source: shared objects file
[0.081s][info][class,load] jdk.internal.vm.vector.VectorSupport source: shared objects file
[0.081s][info][class,load] jdk.internal.vm.vector.VectorSupport$VectorPayload source: shared objects file
[0.081s][info][class,load] jdk.internal.vm.vector.VectorSupport$Vector source: shared objects file
[0.081s][info][class,load] jdk.internal.vm.vector.VectorSupport$VectorMask source: shared objects file
[0.081s][info][class,load] jdk.internal.vm.vector.VectorSupport$VectorShuffle source: shared objects file
[0.081s][info][class,load] jdk.internal.vm.FillerObject source: shared objects file
[0.081s][info][class,load] java.lang.Integer$IntegerCache source: shared objects file
[0.081s][info][class,load] java.lang.Long$LongCache source: shared objects file
[0.081s][info][class,load] java.lang.Byte$ByteCache source: shared objects file
[0.081s][info][class,load] java.lang.Short$ShortCache source: shared objects file
[0.081s][info][class,load] java.lang.Character$CharacterCache source: shared objects file
[0.081s][info][class,load] java.util.jar.Attributes$Name source: shared objects file
[0.081s][info][class,load] java.util.ImmutableCollections$AbstractImmutableMap source: shared objects file
[0.081s][info][class,load] java.util.ImmutableCollections$MapN source: shared objects file
[0.081s][info][class,load] sun.util.locale.BaseLocale source: shared objects file
[0.081s][info][class,load] jdk.internal.module.ArchivedModuleGraph source: shared objects file
[0.081s][info][class,load] java.lang.module.ModuleFinder source: shared objects file
[0.081s][info][class,load] jdk.internal.module.SystemModuleFinders$SystemModuleFinder source: shared objects file
[0.081s][info][class,load] java.util.ImmutableCollections$AbstractImmutableCollection source: shared objects file
[0.081s][info][class,load] java.util.Set source: shared objects file
[0.081s][info][class,load] java.util.ImmutableCollections$AbstractImmutableSet source: shared objects file
[0.081s][info][class,load] java.util.ImmutableCollections$SetN source: shared objects file
[0.081s][info][class,load] java.lang.module.ModuleReference source: shared objects file
[0.081s][info][class,load] jdk.internal.module.ModuleReferenceImpl source: shared objects file
[0.081s][info][class,load] java.lang.module.ModuleDescriptor source: shared objects file
[0.081s][info][class,load] java.lang.module.ModuleDescriptor$Version source: shared objects file
[0.081s][info][class,load] java.util.ImmutableCollections$Set12 source: shared objects file
[0.081s][info][class,load] java.lang.module.ModuleDescriptor$Requires source: shared objects file
[0.081s][info][class,load] java.lang.module.ModuleDescriptor$Requires$Modifier source: shared objects file
[0.081s][info][class,load] java.lang.module.ModuleDescriptor$Exports source: shared objects file
[0.081s][info][class,load] java.lang.module.ModuleDescriptor$Provides source: shared objects file
[0.082s][info][class,load] java.util.ImmutableCollections$AbstractImmutableList source: shared objects file
[0.082s][info][class,load] java.util.ImmutableCollections$List12 source: shared objects file
[0.082s][info][class,load] java.net.URI source: shared objects file
[0.082s][info][class,load] java.util.function.Supplier source: shared objects file
[0.082s][info][class,load] jdk.internal.module.SystemModuleFinders$2 source: shared objects file
[0.082s][info][class,load] jdk.internal.module.ModuleHashes$HashSupplier source: shared objects file
[0.082s][info][class,load] jdk.internal.module.SystemModuleFinders$3 source: shared objects file
[0.082s][info][class,load] java.lang.module.ModuleDescriptor$Opens source: shared objects file
[0.082s][info][class,load] java.util.ImmutableCollections$ListN source: shared objects file
[0.082s][info][class,load] jdk.internal.module.ModuleTarget source: shared objects file
[0.082s][info][class,load] jdk.internal.module.ModuleHashes source: shared objects file
[0.082s][info][class,load] java.util.Collections$UnmodifiableMap source: shared objects file
[0.082s][info][class,load] java.util.HashMap source: shared objects file
[0.082s][info][class,load] java.util.Map$Entry source: shared objects file
[0.082s][info][class,load] java.util.HashMap$Node source: shared objects file
[0.082s][info][class,load] java.lang.module.Configuration source: shared objects file
[0.082s][info][class,load] java.lang.module.ResolvedModule source: shared objects file
[0.082s][info][class,load] java.util.function.Function source: shared objects file
[0.082s][info][class,load] jdk.internal.module.ModuleLoaderMap$Mapper source: shared objects file
[0.082s][info][class,load] java.util.ImmutableCollections source: shared objects file
[0.082s][info][class,load] java.lang.ModuleLayer source: shared objects file
[0.082s][info][class,load] jdk.internal.math.FDBigInteger source: shared objects file
[0.083s][info][class,load] java.lang.NullPointerException source: shared objects file
[0.083s][info][class,load] java.lang.ArithmeticException source: shared objects file
[0.084s][info][class,load] java.io.ObjectStreamField source: shared objects file
[0.084s][info][class,load] java.util.Comparator source: shared objects file
[0.084s][info][class,load] java.lang.String$CaseInsensitiveComparator source: shared objects file
[0.084s][info][class,load] jdk.internal.misc.VM source: shared objects file
[0.084s][info][class,load] java.lang.Module$ArchivedData source: shared objects file
[0.084s][info][class,load] jdk.internal.misc.CDS source: shared objects file
[0.085s][info][class,load] java.util.Objects source: shared objects file
[0.085s][info][class,load] jdk.internal.access.JavaLangReflectAccess source: shared objects file
[0.085s][info][class,load] java.lang.reflect.ReflectAccess source: shared objects file
[0.085s][info][class,load] jdk.internal.access.SharedSecrets source: shared objects file
[0.085s][info][class,load] java.security.PrivilegedAction source: shared objects file
[0.085s][info][class,load] jdk.internal.reflect.ReflectionFactory$GetReflectionFactoryAction source: shared objects file
[0.085s][info][class,load] jdk.internal.reflect.Reflection source: shared objects file
[0.085s][info][class,load] java.lang.StringLatin1 source: shared objects file
[0.085s][info][class,load] java.lang.Math source: shared objects file
[0.086s][info][class,load] jdk.internal.reflect.ReflectionFactory source: shared objects file
[0.086s][info][class,load] jdk.internal.reflect.ReflectionFactory$Config source: shared objects file
[0.086s][info][class,load] jdk.internal.access.JavaLangRefAccess source: shared objects file
[0.086s][info][class,load] java.lang.ref.Reference$1 source: shared objects file
[0.086s][info][class,load] java.lang.ref.ReferenceQueue source: shared objects file
[0.086s][info][class,load] java.lang.ref.NativeReferenceQueue source: shared objects file
[0.086s][info][class,load] java.lang.ref.ReferenceQueue$Null source: shared objects file
[0.086s][info][class,load] java.lang.ref.NativeReferenceQueue$Lock source: shared objects file
[0.086s][info][class,load] jdk.internal.access.JavaLangAccess source: shared objects file
[0.086s][info][class,load] java.lang.System$2 source: shared objects file
[0.086s][info][class,load] jdk.internal.util.SystemProps source: shared objects file
[0.086s][info][class,load] jdk.internal.util.SystemProps$Raw source: shared objects file
[0.096s][info][class,load] java.nio.charset.Charset source: shared objects file
[0.096s][info][class,load] java.nio.charset.spi.CharsetProvider source: shared objects file
[0.096s][info][class,load] sun.nio.cs.StandardCharsets source: shared objects file
[0.096s][info][class,load] sun.nio.cs.HistoricallyNamedCharset source: shared objects file
[0.096s][info][class,load] sun.nio.cs.Unicode source: shared objects file
[0.096s][info][class,load] sun.nio.cs.UTF_8 source: shared objects file
[0.097s][info][class,load] jdk.internal.util.ArraysSupport source: shared objects file
[0.097s][info][class,load] java.util.LinkedHashMap$Entry source: shared objects file
[0.097s][info][class,load] java.util.HashMap$TreeNode source: shared objects file
[0.097s][info][class,load] java.lang.StringConcatHelper source: shared objects file
[0.097s][info][class,load] java.lang.VersionProps source: shared objects file
[0.097s][info][class,load] java.lang.Runtime source: shared objects file
[0.097s][info][class,load] jdk.internal.util.Preconditions source: shared objects file
[0.097s][info][class,load] jdk.internal.util.Preconditions$1 source: shared objects file
[0.097s][info][class,load] java.util.function.BiFunction source: shared objects file
[0.097s][info][class,load] jdk.internal.util.Preconditions$4 source: shared objects file
[0.097s][info][class,load] jdk.internal.util.Preconditions$2 source: shared objects file
[0.097s][info][class,load] jdk.internal.util.Preconditions$3 source: shared objects file
[0.097s][info][class,load] java.util.Arrays source: shared objects file
[0.097s][info][class,load] java.lang.CharacterData source: shared objects file
[0.097s][info][class,load] java.lang.CharacterDataLatin1 source: shared objects file
[0.097s][info][class,load] java.util.concurrent.locks.Lock source: shared objects file
[0.097s][info][class,load] java.util.concurrent.locks.ReentrantLock source: shared objects file
[0.097s][info][class,load] java.util.concurrent.ConcurrentHashMap$Segment source: shared objects file
[0.098s][info][class,load] java.util.concurrent.ConcurrentHashMap$CounterCell source: shared objects file
[0.098s][info][class,load] java.util.concurrent.ConcurrentHashMap$Node source: shared objects file
[0.098s][info][class,load] java.util.concurrent.locks.LockSupport source: shared objects file
[0.098s][info][class,load] java.util.concurrent.ConcurrentHashMap$ReservationNode source: shared objects file
[0.098s][info][class,load] java.util.AbstractSet source: shared objects file
[0.098s][info][class,load] java.util.HashMap$EntrySet source: shared objects file
[0.098s][info][class,load] java.util.HashMap$HashIterator source: shared objects file
[0.098s][info][class,load] java.util.HashMap$EntryIterator source: shared objects file
[0.098s][info][class,load] jdk.internal.util.StaticProperty source: shared objects file
[0.098s][info][class,load] java.io.FileInputStream source: shared objects file
[0.098s][info][class,load] java.io.FileDescriptor source: shared objects file
[0.098s][info][class,load] jdk.internal.access.JavaIOFileDescriptorAccess source: shared objects file
[0.098s][info][class,load] java.io.FileDescriptor$1 source: shared objects file
[0.098s][info][class,load] java.io.Flushable source: shared objects file
[0.098s][info][class,load] java.io.OutputStream source: shared objects file
[0.098s][info][class,load] java.io.FileOutputStream source: shared objects file
[0.098s][info][class,load] java.io.FilterInputStream source: shared objects file
[0.098s][info][class,load] java.io.BufferedInputStream source: shared objects file
[0.098s][info][class,load] jdk.internal.misc.InternalLock source: shared objects file
[0.098s][info][class,load] java.util.concurrent.locks.AbstractQueuedSynchronizer source: shared objects file
[0.098s][info][class,load] java.util.concurrent.locks.ReentrantLock$Sync source: shared objects file
[0.098s][info][class,load] java.util.concurrent.locks.ReentrantLock$NonfairSync source: shared objects file
[0.098s][info][class,load] java.io.FilterOutputStream source: shared objects file
[0.098s][info][class,load] java.io.PrintStream source: shared objects file
[0.098s][info][class,load] jdk.internal.access.JavaIOPrintStreamAccess source: shared objects file
[0.098s][info][class,load] java.io.PrintStream$1 source: shared objects file
[0.098s][info][class,load] java.io.BufferedOutputStream source: shared objects file
[0.098s][info][class,load] java.io.Writer source: shared objects file
[0.098s][info][class,load] java.io.OutputStreamWriter source: shared objects file
[0.098s][info][class,load] sun.nio.cs.StreamEncoder source: shared objects file
[0.100s][info][class,load] java.nio.charset.CharsetEncoder source: shared objects file
[0.100s][info][class,load] sun.nio.cs.UTF_8$Encoder source: jrt:/java.base
[0.100s][info][class,load] java.nio.charset.CodingErrorAction source: shared objects file
[0.100s][info][class,load] java.nio.ByteBuffer source: shared objects file
[0.100s][info][class,load] jdk.internal.misc.ScopedMemoryAccess source: shared objects file
[0.100s][info][class,load] java.nio.Buffer$1 source: shared objects file
[0.100s][info][class,load] jdk.internal.access.JavaNioAccess source: shared objects file
[0.100s][info][class,load] java.nio.Buffer$2 source: shared objects file
[0.100s][info][class,load] java.nio.HeapByteBuffer source: shared objects file
[0.100s][info][class,load] java.nio.ByteOrder source: shared objects file
[0.100s][info][class,load] java.io.BufferedWriter source: shared objects file
[0.100s][info][class,load] java.lang.Terminator source: shared objects file
[0.100s][info][class,load] jdk.internal.misc.Signal$Handler source: shared objects file
[0.100s][info][class,load] java.lang.Terminator$1 source: shared objects file
[0.100s][info][class,load] jdk.internal.misc.Signal source: shared objects file
[0.100s][info][class,load] java.util.Hashtable$Entry source: shared objects file
[0.100s][info][class,load] jdk.internal.misc.Signal$NativeHandler source: shared objects file
[0.100s][info][class,load] jdk.internal.misc.OSEnvironment source: shared objects file
[0.100s][info][class,load] java.lang.Thread$State source: shared objects file
[0.100s][info][class,load] java.lang.ref.Reference$ReferenceHandler source: shared objects file
[0.100s][info][class,load] java.lang.Thread$ThreadIdentifiers source: shared objects file
[0.100s][info][class,load] java.lang.ref.Finalizer$FinalizerThread source: shared objects file
[0.100s][info][class,load] jdk.internal.ref.Cleaner source: shared objects file
[0.101s][info][class,load] java.util.Collections source: shared objects file
[0.101s][info][class,load] jdk.internal.misc.Blocker source: shared objects file
[0.101s][info][class,load] java.util.Collections$EmptySet source: shared objects file
[0.101s][info][class,load] java.util.concurrent.locks.Condition source: shared objects file
[0.101s][info][class,load] java.util.Collections$EmptyList source: shared objects file
[0.101s][info][class,load] java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject source: shared objects file
[0.101s][info][class,load] java.util.Collections$EmptyMap source: shared objects file
[0.101s][info][class,load] java.lang.IllegalArgumentException source: shared objects file
[0.101s][info][class,load] java.lang.invoke.MethodHandleStatics source: shared objects file
[0.101s][info][class,load] java.lang.reflect.ClassFileFormatVersion source: shared objects file
[0.101s][info][class,load] sun.security.action.GetPropertyAction source: shared objects file
[0.101s][info][class,load] jdk.internal.util.ClassFileDumper source: shared objects file
[0.102s][info][class,load] java.util.HexFormat source: shared objects file
[0.102s][info][class,load] java.util.concurrent.atomic.AtomicInteger source: shared objects file
[0.102s][info][class,load] jdk.internal.module.ModuleBootstrap source: shared objects file
[0.102s][info][class,load] java.lang.invoke.MethodHandles source: shared objects file
[0.102s][info][class,load] java.lang.invoke.MemberName$Factory source: shared objects file
[0.102s][info][class,load] java.lang.invoke.MethodHandles$Lookup source: shared objects file
[0.102s][info][class,load] java.lang.StrictMath source: shared objects file
[0.102s][info][class,load] java.util.ImmutableCollections$MapN$1 source: shared objects file
[0.102s][info][class,load] java.util.ImmutableCollections$MapN$MapNIterator source: shared objects file
[0.102s][info][class,load] java.util.KeyValueHolder source: shared objects file
[0.102s][info][class,load] sun.invoke.util.VerifyAccess source: shared objects file
[0.103s][info][class,load] java.lang.reflect.Modifier source: shared objects file
[0.103s][info][class,load] jdk.internal.access.JavaLangModuleAccess source: shared objects file
[0.103s][info][class,load] java.lang.module.ModuleDescriptor$1 source: shared objects file
[0.103s][info][class,load] java.io.File source: shared objects file
[0.103s][info][class,load] java.io.DefaultFileSystem source: shared objects file
[0.103s][info][class,load] java.io.FileSystem source: shared objects file
[0.103s][info][class,load] java.io.UnixFileSystem source: shared objects file
[0.103s][info][class,load] jdk.internal.module.ModulePatcher source: shared objects file
[0.103s][info][class,load] java.util.HashSet source: shared objects file
[0.103s][info][class,load] jdk.internal.module.ModuleBootstrap$Counters source: shared objects file
[0.103s][info][class,load] jdk.internal.module.ArchivedBootLayer source: shared objects file
[0.103s][info][class,load] jdk.internal.access.JavaNetUriAccess source: shared objects file
[0.103s][info][class,load] java.net.URI$1 source: shared objects file
[0.103s][info][class,load] jdk.internal.loader.ArchivedClassLoaders source: shared objects file
[0.103s][info][class,load] jdk.internal.loader.URLClassPath source: shared objects file
[0.103s][info][class,load] java.net.URLStreamHandlerFactory source: shared objects file
[0.103s][info][class,load] java.net.URL$DefaultFactory source: shared objects file
[0.103s][info][class,load] jdk.internal.access.JavaNetURLAccess source: shared objects file
[0.103s][info][class,load] java.net.URL$3 source: shared objects file
[0.104s][info][class,load] java.io.File$PathStatus source: shared objects file
[0.104s][info][class,load] sun.net.www.ParseUtil source: shared objects file
[0.104s][info][class,load] java.net.URLStreamHandler source: shared objects file
[0.104s][info][class,load] sun.net.www.protocol.file.Handler source: shared objects file
[0.104s][info][class,load] sun.net.util.IPAddressUtil source: shared objects file
[0.104s][info][class,load] sun.net.util.IPAddressUtil$MASKS source: shared objects file
[0.104s][info][class,load] java.util.Queue source: shared objects file
[0.104s][info][class,load] java.util.Deque source: shared objects file
[0.104s][info][class,load] java.util.ArrayDeque source: shared objects file
[0.104s][info][class,load] sun.net.www.protocol.jar.Handler source: shared objects file
[0.104s][info][class,load] jdk.internal.loader.ClassLoaders$BootClassLoader source: shared objects file
[0.104s][info][class,load] java.security.cert.Certificate source: shared objects file
[0.104s][info][class,load] java.lang.ClassLoader$ParallelLoaders source: shared objects file
[0.104s][info][class,load] java.util.WeakHashMap source: shared objects file
[0.104s][info][class,load] java.util.WeakHashMap$Entry source: shared objects file
[0.104s][info][class,load] java.util.Collections$SetFromMap source: shared objects file
[0.104s][info][class,load] java.util.WeakHashMap$KeySet source: shared objects file
[0.105s][info][class,load] jdk.internal.access.JavaSecurityAccess source: shared objects file
[0.105s][info][class,load] java.security.ProtectionDomain$JavaSecurityAccessImpl source: shared objects file
[0.105s][info][class,load] java.security.ProtectionDomain$Key source: shared objects file
[0.105s][info][class,load] java.security.Principal source: shared objects file
[0.105s][info][class,load] jdk.internal.loader.NativeLibraries source: shared objects file
[0.105s][info][class,load] jdk.internal.loader.ClassLoaderHelper source: shared objects file
[0.105s][info][class,load] jdk.internal.util.OSVersion source: shared objects file
[0.105s][info][class,load] java.util.concurrent.ConcurrentHashMap$CollectionView source: shared objects file
[0.105s][info][class,load] java.util.concurrent.ConcurrentHashMap$KeySetView source: shared objects file
[0.105s][info][class,load] jdk.internal.module.ServicesCatalog source: shared objects file
[0.105s][info][class,load] jdk.internal.loader.AbstractClassLoaderValue source: shared objects file
[0.105s][info][class,load] jdk.internal.loader.ClassLoaderValue source: shared objects file
[0.105s][info][class,load] java.util.Optional source: shared objects file
[0.105s][info][class,load] jdk.internal.loader.BootLoader source: shared objects file
[0.105s][info][class,load] java.lang.Module$EnableNativeAccess source: shared objects file
[0.106s][info][class,load] jdk.internal.loader.BuiltinClassLoader$LoadedModule source: shared objects file
[0.106s][info][class,load] java.util.ImmutableCollections$SetN$SetNIterator source: shared objects file
[0.106s][info][class,load] java.util.ImmutableCollections$Set12$1 source: shared objects file
[0.107s][info][class,load] java.util.ListIterator source: shared objects file
[0.107s][info][class,load] java.util.ImmutableCollections$ListItr source: shared objects file
[0.107s][info][class,load] jdk.internal.module.ModuleLoaderMap source: shared objects file
[0.110s][info][class,load] jdk.internal.loader.AbstractClassLoaderValue$Memoizer source: shared objects file
[0.110s][info][class,load] jdk.internal.module.ServicesCatalog$ServiceProvider source: shared objects file
[0.110s][info][class,load] java.util.concurrent.CopyOnWriteArrayList source: shared objects file
[0.110s][info][class,load] java.util.HashMap$KeySet source: shared objects file
[0.110s][info][class,load] java.util.HashMap$KeyIterator source: shared objects file
[0.110s][info][class,load] java.lang.ModuleLayer$Controller source: shared objects file
[0.110s][info][class,load] java.lang.invoke.StringConcatFactory source: shared objects file
[0.111s][info][class,load] com.person.Person source: ./abc2.jar
Exception in thread "main" [0.116s][info][class,load] java.lang.Throwable$PrintStreamOrWriter source: jrt:/java.base
[0.116s][info][class,load] java.lang.Throwable$WrappedPrintStream source: jrt:/java.base
[0.116s][info][class,load] java.util.IdentityHashMap source: shared objects file
[0.116s][info][class,load] java.util.IdentityHashMap$KeySet source: shared objects file
[0.116s][info][class,load] java.lang.Readable source: shared objects file
[0.116s][info][class,load] java.nio.CharBuffer source: shared objects file
[0.116s][info][class,load] java.nio.HeapCharBuffer source: shared objects file
[0.116s][info][class,load] java.lang.StringCoding source: shared objects file
[0.116s][info][class,load] java.nio.charset.CoderResult source: shared objects file
[0.116s][info][class,load] java.util.concurrent.ForkJoinWorkerThread source: shared objects file
[0.116s][info][class,load] jdk.internal.misc.CarrierThread source: shared objects file
java.lang.NoClassDefFoundError: com.person.Person
2024/07/12 16:58:22 class not found, err: Java exception occurred. check stderr/logcat
exit status 1

Any recommendations/suggestions to solve this?

How to run the main method in java?

java code:
public class GoSdkApplication {

public static void main(String[] args) {
    System.out.println(args[0]);
}

}
go code:
package main

import (
"log"
"runtime"

"github.com/timob/jnigi"

)

func main() {

if err := jnigi.LoadJVMLib(jnigi.AttemptToFindJVMLibPath()); err != nil {
	log.Fatal(err)
}

runtime.LockOSThread()

jvm, env, err := jnigi.CreateJVM(jnigi.NewJVMInitArgs(false, true, jnigi.DEFAULT_VERSION, []string{"-Djava.class.path=/Users/andy/gosdk.jar"}))

obj, err := env.NewObject("com/weixun/openapi/GoSdkApplication")
if err != nil {
	log.Fatal(err)
}
err = obj.CallMethod(env, "main", jnigi.Object, "plainText")
if err != nil {
	log.Fatal(err)
}

if err := jvm.Destroy(); err != nil {
	log.Fatal(err)
}

}
,The following error isException in thread "main" java.lang.NoClassDefFoundError: com/weixun/openapi/GoSdkApplication Caused by: java.lang.ClassNotFoundException: com.weixun.openapi.GoSdkApplication at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) 2024/08/09 16:04:56 Java exception occurred. check stderr/logcat exit status 1,Please help me with this problem, much appreciated

NoSuchMethodError

img

err = jnigi.LoadJVMLib(jnigi.AttemptToFindJVMLibPath());

if err != nil {
	fmt.Println(err);
	return;
}


opts := jnigi.NewJVMInitArgs(false, true, jnigi.JNI_VERSION_1_8, []string{"-Djava.class.path=java/lire.jar:java/liresolr.jar"});

_, env, err := jnigi.CreateJVM(opts);

if err != nil {
	fmt.Println(err);
	return;
}

data, err := env.CallStaticMethod(
	"net/semanticmetadata/lire/solr/indexing/ParallelSolrIndexer",
	"hashImage",
	jnigi.ObjectType("java/lang/String"),
	env.NewByteArrayFromSlice(frame),
	"test",
	"123");

if err != nil {
	fmt.Println(err);
	return;
}

fmt.Println(data);

I know the classpath is correct and it detects the class but it cannot find my static method.
any idea as to why it cant find my method?

Add documentation

Need to add Godoc to document types and methods. How the JNI library is loaded on different systems, how signal handling works.

Change the module name. Feedback please

I see this repo has quite a few forks, most of these have changed the name of the module to their respective names on github.

Currently it's tekao.net/jnigi which is running on domain/hosting I own which points back to this repo. So builds working rely on my personal infrastructure being available, which is probably less reliable than github's.

We could change it to:

  • github.com/timob/jnigi (this is what is was originally)
  • github.com/jnigi-project/jnigi
  • something else

I've done some work to make the github experience better. We have automated builds/tests now on PRs and master branch. I've updated the tests to use stretchr/testify/assert module.

I think the project is at quite a stable state so if I can get some feedback here and more testing coverage, i would probably look taging version 2.

JNI ID caching

Currently we cache class IDs (uintptr) so they don't need to be found using the findClass JNI function.

But not method IDs which we call getMethodID for in each CallMethod. The same is true for field IDs. We could start caching these two types of IDs too.

We currently create global references to class IDs (which are objects), so method and field IDs should remain valid while we hold this global reference.

How registerNative method use?

I want to register a Go function as a java native method, the program not throw error, but execution result not as expect.

package main

/*
	#include <stdlib.h>

	extern void Test(_GoString_ arg1,_GoString_ arg2);

*/
import "C"
import (
	"fmt"
	"log"
	"runtime"
	"unsafe"

	"tekao.net/jnigi"
)

var A map[string]string

func init() {
	A = make(map[string]string)
}

var env *jnigi.Env
var jvm *jnigi.JVM

type GoString string

func (g *GoString) ConvertToGo(obj *jnigi.ObjectRef) error {
	defer env.DeleteLocalRef(obj)
	var goBytes []byte
	if err := obj.CallMethod(env, "getBytes", &goBytes); err != nil {
		return err
	}
	*g = GoString(goBytes)
	return nil
}

func (g *GoString) ConvertToJava() (obj *jnigi.ObjectRef, err error) {
	return env.NewObject("java/lang/String", []byte(string(*g)))
}

func (g *GoString) GetClassName() string {
	return "java/lang/String"
}

func (g *GoString) IsArray() bool {
	return false
}

type TestFunc func(string, string)

//export Test
func Test(key string, value string) {
	fmt.Println(key)
	fmt.Println(value)
	A[key] = value
	fmt.Println(A[key])
}

func main() {
	C.Test("A", "b")

	println(A["A"])
	if err := jnigi.LoadJVMLib("/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/server/libjvm.dylib"); err != nil {
		log.Fatal(err)
	}
	runtime.LockOSThread()
	jarPath := "/Users/kaichen/Documents/projects/jni-java-test/target/jni-java-test-1.0-SNAPSHOT.jar"
	var err error
	jvm, env, err = jnigi.CreateJVM(jnigi.NewJVMInitArgs(false, true, jnigi.JNI_VERSION_1_8, []string{"-Xcheck:jni", "-Xrs", fmt.Sprintf("-Djava.class.path=%s", jarPath)}))
	if err != nil {
		log.Fatal(err)
	}

	var a TestFunc
	a = Test
	err = env.RegisterNative("abc/Test", "put", jnigi.Void, []interface{}{"java/lang/String", "java/lang/String"}, unsafe.Pointer(&a))
	if err != nil {
		log.Fatal(err)
	}
	test := jnigi.NewObjectRef("abc/Test")
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; i < 12; i++ {
		_ = test.CallMethod(env, "put", nil, GoString("B"), GoString("a"))
	}
	println(A["B"])
	//world, err := env.NewObject("java/lang/String", []byte("World!"))
	//if err != nil {
	//	log.Fatal(err)
	//}
	//
	//greeting := jnigi.NewObjectRef("java/lang/String")
	//err = hello.CallMethod(env, "concat", greeting, world)
	//if err != nil {
	//	log.Fatal(err)
	//}
	//
	//var goGreeting []byte
	//err = greeting.CallMethod(env, "getBytes", &goGreeting)
	//if err != nil {
	//	log.Fatal(err)
	//}
	//
	//// Prints "Hello World!"
	//fmt.Printf("%s\n", goGreeting)
	//
	if err = jvm.Destroy(); err != nil {
		log.Fatal(err)
	}
}
package abc;

/**
 * Created by IntelliJ IDEA.
 * Author: kaichen
 * Date: 2022/7/16
 * Time: 21:17
 */
public class Test {
    public native void put(String key, String value);
}

go won't wait the java thread finish

i try to use JNIGI to call a .jar main method(using thread inside the jar program, should took 5x sec to run)
but the go program ended so fast()

package threading;
public class TestThread implements Runnable{
	@Override
	public void run()  {
		System.out.println("here is TestThread");
        try{
            System.out.println("try");
            int i=0;
            while(i< 10){
                System.out.println("here is looping: "+i);
                Thread.sleep(5000);
                i++;
            }
        }catch(Exception e){
		    System.out.println("exception on sleep");
        }
		System.out.println("here is TestThread after sleep");
	}
}
import threading.TestThread;
public class Main{
    public static void main(String [] args){
    	System.out.println("here is Main");

        Thread tt = new Thread(new TestThread());
        tt.start();
    	System.out.println("here is Main 8");

    }
}

Expose FindClass

Hey,
Is there any way to retrieve java/lang/Class without having to call java/lang/Class.forName (Doesn't work with external libraries)?
Why can't we just export callFindClass?

Best regards

suppress (or fix) warnings

How do I suppress (or ideally fix) these warnings from popping up in the console?

Warning: SIGUSR1 handler expected:0x0000000000000000  found:___dev2_go+0x58b30
Signal Handlers:
SIGSEGV: [libjvm.so+0x8b2170], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGBUS: [libjvm.so+0x8b2170], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGFPE: [libjvm.so+0x8b2170], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGPIPE: [libjvm.so+0x8b2170], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGXFSZ: [libjvm.so+0x8b2170], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGILL: [libjvm.so+0x8b2170], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGUSR1: [___dev2_go+0x58b30], sa_mask[0]=11111111011111111101111111111111, sa_flags=SA_ONSTACK|SA_RESTART|SA_SIGINFO
SIGUSR2: [libjvm.so+0x8b2020], sa_mask[0]=00100000000000000000000000000000, sa_flags=SA_RESTART|SA_SIGINFO
SIGHUP: [libjvm.so+0x8b24f0], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGINT: [libjvm.so+0x8b24f0], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGTERM: [libjvm.so+0x8b24f0], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
SIGQUIT: [libjvm.so+0x8b24f0], sa_mask[0]=11111111011111111101111111111110, sa_flags=SA_RESTART|SA_SIGINFO
WARNING: JNI local refs: 33, exceeds capacity: 32
WARNING: JNI local refs: 33, exceeds capacity: 32
WARNING: JNI local refs: 33, exceeds capacity: 32
WARNING: JNI local refs: 66, exceeds capacity: 65
WARNING: JNI local refs: 66, exceeds capacity: 65
WARNING: JNI local refs: 66, exceeds capacity: 65
WARNING: JNI local refs: 99, exceeds capacity: 98
WARNING: JNI local refs: 99, exceeds capacity: 98
WARNING: JNI local refs: 99, exceeds capacity: 98

jni.h: No such file or directory

I found your awsome library to use jni with go lang.
but I got this error message on my Ubuntu 16.04 LTS.

jni.h: No such file or directory

I already install openjdk7 but this error occured... Is there any way to solve this problem?

How to express generics

How to express this type in golang:List
Statement type is interface

java:List statementList = new ArrayList();
golang:jnigi.NewObjectArrayRef("java/util/List")

Dockerfile example

Hi, I am trying to dockerize an application and getting an error on the build stage as follows:

/go/src/github.com/timob/jnigi/cinit.go:8:9: fatal error: jni.h: No such file or directory
8 | #include<jni.h>
| ^~~~~~~
compilation terminated.

My Dockerfile:

FROM golang:alpine as BUILD

ENV GO111MODULE=auto

RUN apk update && \
    apk upgrade && \
    apk add git && \
    apk add unzip && \ 
    apk add openssl-dev && \
    apk add build-base && \
    apk add --no-cache gcc musl-dev && \
    apk add --no-cache openjdk8-jre

COPY . /go/src/project
WORKDIR /go/src/project

RUN go get -d -v

RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /go/dist/app

FROM alpine:latest AS FINAL

COPY --from=BUILD /go/dist/app /project-runtime/app

RUN apk update && \
    apk add tzdata && \
    apk add apr && \
    apk add ca-certificates && rm -rf /var/cache/apk/* \
    apk add openssl

RUN update-ca-certificates

WORKDIR /project-runtime

ENTRYPOINT ["./app"]

The error happens when the "RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /go/dist/app" is executed. How should I add the jni.h file? Could you please help me?

concurrent JVMs

I'm trying to have many JVMs running on concurrent functions (in main()):

for i := 0; i < nProcessPass; i++{
		slice = csvSlices[i*sliceSize:(i+1)*sliceSize]
		go processPass(slice, resultChan)
	}

where processPass instantiates its own JVM (with a .jar classpath):


func processPass(slice [][]string, resultChan chan string){
	//start JVM
	_, env, err := jnigi.CreateJVM(jnigi.NewJVMInitArgs(false, true, jnigi.DEFAULT_VERSION, []string{"-Xcheck:jni", "-Djava.class.path=/home/bernardo/go/src/github.com/bernardoaraujor/corinda/passfault_corinda/out/artifacts/passfault_corinda_jar/passfault_corinda.jar"}))
	if err != nil {
		log.Fatal(err)
	}

	//create TextAnalysis JVM object
	obj, err := env.NewObject("org/owasp/passfault/TextAnalysis")
	if err != nil {
		log.Fatal(err)
	}

	for _, value := range slice{
		fmt.Println(value)

		//create JVM string with password
		str, err := env.NewObject("java/lang/String", []byte(value[2]))

		//call passwordAnalysis on password
		v, err := obj.CallMethod(env, "passwordAnalysis", "java/lang/String", str)
		if err != nil {
			log.Fatal(err)
		}

		//format result from JVM into Go string
		resultJVM, err := v.(*jnigi.ObjectRef).CallMethod(env, "getBytes", jnigi.Byte|jnigi.Array)
		resultGo := string(resultJVM.([]byte))

		fmt.Println(resultGo)
	}
}

am I doing something wrong? or jnigi just can't have multiple JVMs running concurrently?

Go module version

Will it be possible to add standard go module version definition?

Currently these are being resolved as pseudo versions "github.com/timob/jnigi v0.0.0-20200813090134-4fe21c71566a" instead of canonical "vA.B.C" ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.