0

I've successfully generated proxies from Java to .NETusing jni4net proxygen. I'm now trying to create a .NET solution in Visual Studio 2017 and use the Java proxies in a .NET console program. I've imported the .dlls from the proxygeneration and it seems to work since Visual Studio is auto-filling my Java classes (TempClientMain) and is not showing any errors.

namespace ConsoleApp1
class Program 
{
     static void Main() 
     {
         var setup = new BridgeSetup(string[] args);
         setup.Verbose = true;
         setup.AddAllJarsClassPath("./");

         Bridge.CreateJVM(setup);
         Bridge.RegisterAssembly(typeof(TempClientMain).Assembly);

         TempClientMain test = new TempClientMain();
         test.run();
     }
}

When I however build and run it I get the following cmd output:

loading core from C:/Users/Ruben/source/repos/ConsoleApp1/ConsoleApp1/bin/x64/Debug/jni4net.n-0.8.8.0.DLL
loading jni4net.n-0.8.8.0, Version=0.8.8.0, Culture=neutral, PublicKeyToken=134a23405600bab4 from C:\Users\Ruben\source\repos\ConsoleApp1\ConsoleApp1\bin\x64\Debug\jni4net.n-0.8.8.0.dll
loaded jni4net.n-0.8.8.0, Version=0.8.8.0, Culture=neutral, PublicKeyToken=134a23405600bab4 from C:\Users\Ruben\source\repos\ConsoleApp1\ConsoleApp1\bin\x64\Debug\jni4net.n-0.8.8.0.dll
Initialized jni4net core
core loaded from C:/Users/Ruben/source/repos/ConsoleApp1/ConsoleApp1/bin/x64/Debug/jni4net.n-0.8.8.0.DLL
clr.version         :v4.0.30319
clr.arch            :64bit
java.home           :C:\Program Files\Java\jdk1.8.0_161
java.version        :1.8.0_161
sun.arch.data.model :64
loading mediasense.j4n, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null from C:\Users\Ruben\source\repos\ConsoleApp1\ConsoleApp1\bin\x64\Debug\mediasense.j4n.dll

Unhandled Exception: net.sf.jni4net.jni.JNIException: Can't load java class for *MY TARGET PACKAGE PATH* from classLoader sun.misc.Launcher$AppClassLoader@c387f44 ---> java.lang.ClassNotFoundException: *MY TARGET PACKAGE PATH*
   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 ConsoleApp1.Program.Main(String[] args) in C:\Users\Ruben\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 21
Press any key to continue . . .

It loads fine but it doesnt seem to find the target folder. Where I've written MY TARGET PACKAGE PATH a package path that is identical to the proxygens target folder is shown (there are no uppercase letters). Where am I supposed to put this so the .NET program can find it? I've tried pasting the folder in the project root and the finished build folder. I also get the error when not including it at all. I'm not very familiar with Visual Studio so is there another way than just pasting it to include it?

1 Answer 1

0

I was just missing a jar file from the Java project in the build output folder. It was confusing since the package path wasn't refering to that jar file at all but it worked adding it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.