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

1.8k Views Asked by At

I built a very small and simple helloWorld program in java (has interface and in class has system.lang.out.println("hello world"))). I wrapped it with proxy gen. Now that I'm trying to attach it to c# (going by meCalc example) I get the following error:

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)

my c# code:

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

Why is that so? What am I doing wrong and how can I fix it to work?

1

There are 1 best solutions below

0
On BEST ANSWER

found out java packages may not contain any uppercase letters. the original JAR and the j4n.jar have to be in the same folder as the exe file. also when adding them to project make sure that in the properties they are marked as "copy always" thankyou @Tetsuya Yamamoto

also i found this link which might help someone troubleshoot http://jni4net.com/troubleshoot.html