在 jni4net java.lang.ClassNotFoundException 中使用 java 的 jni4net c#

jni4net c# with java in jni4net java.lang.ClassNotFoundException

我在 java 中构建了一个非常小而简单的 helloWorld 程序(有界面,在 class 中有 system.lang.out.println("hello world")))。我用 proxy gen 包装了它。现在我正在尝试将它附加到 c#(以 meCalc 为例)我收到以下错误:

Unhandled Exception: net.sf.jni4net.jni.JNIException: Can't load java class for dt09120958.HelloWorld09120958 from classLoader sun.misc.Launcher$AppClassLoader@c387f44 ---> java.lang.ClassNotFoundException: dt09120958.HelloWorld09120958 at net.sf.jni4net.jni.JNIEnv.ExceptionTest() at net.sf.jni4net.jni.JNIEnv.CallObjectMethodPtr(IJvmProxy obj, MethodId methodIdNative, Value[] args) at java.lang.ClassLoader.loadClass(String par0) at net.sf.jni4net.utils.Registry.LoadClass(String name, ClassLoader classLoader, JNIEnv env) --- End of inner exception stack trace --- at net.sf.jni4net.utils.Registry.LoadClass(String name, ClassLoader classLoader, JNIEnv env) at net.sf.jni4net.utils.Registry.RegisterClass(RegistryRecord record, ClassLoader classLoader, JNIEnv env) at net.sf.jni4net.utils.Registry.BindJvm(RegistryRecord record, ClassLoader classLoader, JNIEnv env) at net.sf.jni4net.utils.Registry.BindJvm(RegistryRecord record, JNIEnv env) at net.sf.jni4net.utils.Registry.RegisterType(Type type, Boolean bindJVM, JNIEnv env) at net.sf.jni4net.utils.Registry.RegisterAssembly(Assembly assembly, Boolean bindJVM) at net.sf.jni4net.Bridge.RegisterAssembly(Assembly assembly) at netdt09120958.Program.Main(String[] args)

我的 C# 代码:

 static void Main(string[] args)
            {
                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(HelloWorld09120958).Assembly);

                IHelloWorld09120958 calc = new HelloWorld09120958();
                calc.SayHello();
                Console.ReadKey();
            }

为什么会这样?我做错了什么,我该如何解决它才能正常工作?

发现 java 包可能不包含任何大写字母。 原始 JAR 和 j4n.jar 必须与 exe 文件位于同一文件夹中。另外,将它们添加到项目时,请确保在属性中将它们标记为 "copy always" 谢谢@Tetsuya Yamamoto

我还发现了这个 link 这可能有助于解决问题 http://jni4net.com/troubleshoot.html