The objective is to simplify the use of Jni4Net, and to hide the complexity in consuming Java code from .NET:
Here are a couple examples of these Extension Methods in action:
When you create a simple Jni4Net bridge there is only one jar loader:
Next lets load a jar dynamically and see it appear in the list of loaded jars
Note that once the jar is loaded we can access its classes:
create instances and invoke methods:
here is the script show above:
var jni4Net = new API_Jni4Net().setUpBride(); var env = jni4Net.jniEnv; var classLoader = ClassLoader.getSystemClassLoader(); var beanShellJar = "http://www.beanshell.org/bsh-2.0b4.jar" .uri() .download(false); classLoader.loadJar(beanShellJar); var interpreter_Class = beanShellJar.java_Jar_Class("bsh.Interpreter"); return interpreter_Class.newInstance() .java_Invoke_UsingSignature( "eval", "(Ljava/lang/String;)Ljava/lang/Object;", "return \"hello from java: \" + (2 + 2); ".java_String()).str(); return classLoader.jarsInClassPath(); //using java.lang; //O2File:API_Jni4Net.cs //O2Ref:jni4net.n-0.8.6.0.dll
Finally we can also load/add to the system class path, entire folders with jars. For example all ESAPI dependencies: