Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run the main method in java? #87

Open
andy-hsiung opened this issue Aug 9, 2024 · 0 comments
Open

How to run the main method in java? #87

andy-hsiung opened this issue Aug 9, 2024 · 0 comments

Comments

@andy-hsiung
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant