I need to reference a .Net dll in java. I have used jni4net libraries for the same. I have followed the steps mentioned in the video below :
https://www.youtube.com/watch?time_continue=351&v=8OoSK_RWUe4
I have followed all the steps required to reference jni4net libraries but i get the following runtime Exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: orionforpython.DynamicOrion.__ctorDynamicOrion0(Lnet/sf/jni4net/inj/IClrProxy;)V
at orionforpython.DynamicOrion.__ctorDynamicOrion0(Native Method)
at orionforpython.DynamicOrion.<init>(DynamicOrion.java:25)
at com.orion.OrionForJava.main(OrionForJava.java:16)
After following all the steps, This is my code:
package com.orion;
import net.sf.jni4net.Bridge;
import orionforpython.*;
import java.io.*;
class OrionForJava {
public static void main(String[] args) throws IOException {
Bridge.setVerbose(true);
Bridge.init();
File proxyAssemblyFile=new File("OrionForPython.dll");
Bridge.LoadAndRegisterAssemblyFrom(proxyAssemblyFile);
DynamicOrion orion=new DynamicOrion();
String res=orion.ReqLogin("user", "pwd", "");
System.out.print(res);
}}
I have tried executing the same using NetBeans 8.1 IDE but with no success. I am using jni4net-0.8.8.0 version and Eclipse IDE for Java Developers Version: Oxygen.3 Release (4.7.3) Any assistance would be helpful!
I used jni4net library to call c# dlls from java and it is working fine. I used a lightly different approach to initialize jni4net.
try {
Bridge.setVerbose(true);
Bridge.init(new File("Full path to jni4net.n.w64.v40-0.8.8.0.dll"));
// where dlls to load is jni4net.n.w64.v40-0.8.8.0.dll,jni4net.n-0.8.8.0.dll,MyOriginalNETDll.dll,MyOriginalNETDll.j4n.dll (after proxygen processing)
for (String str : dllsToLoad) {
File dll = new File(rutaDlls + str);
Bridge.LoadAndRegisterAssemblyFrom(dll);
}
} catch (IOException e) {
LOG.error("Error jniBrige.", e);
}
I needed to use full path c:... to the dll to make it work. I also had to take care about .net framework version used to create assembly (need to use 4.0 in my case and java version 8)
Hopes this helps