I have a simple Java class called jniBridge.Calculator that has one simple method Add(int a, int b). After building the project using eclipse, i exported the project as a JAR file.
I then called proxygen on the JAR file, this produced a folder called clr and another folder called jvm that contained both the C# and Java proxies respectively. Proxygen also created a build.cmd and an .xml files as well.
After that i ran the build.cmd it produced a .DLL and .JAR file.
Now i want to use these or whatever in C#, so i copied the .DLL and .JAR files into the .NET project folder and added a reference to the .DLL file and set the .JAR file to Copy Always to the output folder so that it exists along side the .EXE file. I also added a reference to the Jni4Net main library file jni4net.n-0.8.8.0.dll and copied its main JAR file, jni4net.j-0.8.8.0.jar, to the same directory. Adding to the dump, i also added the original JAR file i started with.
Inside the C# Program.cs i do the following:
static void Main(string[] args)
{
var bridgeSetup = new BridgeSetup();
bridgeSetup.Verbose = true;
bridgeSetup.AddAllJarsClassPath("./");
bridgeSetup.IgnoreJavaHome = true;
//bridgeSetup.AddAllJarsClassPath(@"C:\Program Files\Java\jre7");
Bridge.CreateJVM(bridgeSetup);
Bridge.RegisterAssembly(typeof(DemoCalc).Assembly);
ICalc calc = new DemoCalc();
int result = calc.MySuperSmartFunctionIDontHaveInJava("Answer to the Ultimate Question of Life, the Universe, and Everything");
Console.WriteLine("Answer to the Ultimate Question is : " + result);
}
However, the last invocation fails with the following exception:
net.sf.jni4net.jni.JNIException HResult=-2146233088 Message=Can't load java class for democalc.DemoCalc from classLoader sun.misc.Launcher$AppClassLoader@20eb607d Source=jni4net.n-0.8.8.0 StackTrace: 在 net.sf.jni4net.utils.Registry.LoadClass(String name, ClassLoader classLoader, JNIEnv env) 在 net.sf.jni4net.utils.Registry.RegisterClass(RegistryRecord record, ClassLoader classLoader, JNIEnv env)
Any help please!!