c# - jni4net failed to load DLLs in Java app -
i'm trying modify jni4net sample code mycsharpdemocalc
, , make sample bridge between .net dll , java layer. here c# code:
using system; using dynamsoft.dotnet.twain; namespace mycsharpdemocalc { public interface icalc { int mysupersmartfunctionidonthaveinjava(string question); bool isshowui(); } public class democalc : icalc { private readonly random r = new random(); private dynamicdotnettwain dynamicdotnettwain; public democalc() { dynamicdotnettwain = new dynamsoft.dotnet.twain.dynamicdotnettwain(); } public int mysupersmartfunctionidonthaveinjava(string question) { if (question == "answer ultimate question of life, universe, , everything") { return 42; } return r.next(); } public bool isshowui() { return dynamicdotnettwain.ifshowui; } } }
in order build successfully, added following references:
- system.windows.forms
- dynamicdotnettwain
then typed in command
proxygen.exe mycsharpdemocalc.dll -wd work
to generate mycsharpdemocalc.j4n.jar
and mycsharpdemocalc.j4n.dll
.
now, can import dynamicdotnettwain.dll, mycsharpdemocalc.j4n.dll, jni4net.n.w64.v20-0.8.6.0.dll, jni4net.n-0.8.6.0.dll, jni4net.j-0.8.6.0.jar , mycsharpdemocalc.j4n.jar java project.
java code:
import net.sf.jni4net.bridge; import java.io.ioexception; import mycsharpdemocalc.democalc; import mycsharpdemocalc.icalc; public class program { public static void main(string arsg[]) throws ioexception { bridge.setclrversion("v20"); bridge.init(); bridge.loadandregisterassemblyfrom(new java.io.file("dynamicdotnettwain.dll")); bridge.loadandregisterassemblyfrom(new java.io.file("mycsharpdemocalc.j4n.dll")); // crashed icalc calc = new democalc(); final int result = calc.mysupersmartfunctionidonthaveinjava("answer ultimate question of life, universe, , everything"); system.out.printf("answer ultimate question : " + result); system.out.printf("if show ui : " + calc.isshowui()); } }
when tried run application, crashed at
bridge.loadandregisterassemblyfrom(new java.io.file("mycsharpdemocalc.j4n.dll"));
exception in thread "main" system.reflection.reflectiontypeloadexception: unable load 1 or more of requested types. retrieve loaderexceptions property more information. @ system.reflection.module._gettypesinternal(stackcrawlmark& stackmark) @ system.reflection.assembly.gettypes() @ net.sf.jni4net.utils.registry.registerassembly(assembly assembly, boolean bindjvm, classloader classloader) @ net.sf.jni4net.bridge.registerassembly(assembly assembly, classloader classloader) @ net.sf.jni4net.bridge.loadandregisterassemblyfromclassloader(file assemblyfile, classloader classloader) @ net.sf.jni4net.bridge.loadandregisterassemblyfrom(file assemblyfile) @ net.sf.jni4net.__bridge.loadandregisterassemblyfrom3(intptr __envp, jnilocalhandle __class, jnilocalhandle assemblyfile) @ net.sf.jni4net.bridge.loadandregisterassemblyfrom(native method) @ com.main.program.main(program.java:68)
how can fix it? thanks!
the jni4net attempt load image jni4net libraries located at, workaround (afaik) copy whole libraries source directory, , compile package using copied libraries, work.
Comments
Post a Comment