Wedde said:
Can I use JNI to implement it?
It depends on how you'll invoke the java class. I've succesfully used
the following method.
Pre:
- The java class is contained in a .jar file.
- The .jar file is compatible with the Microsoft JRE.
- The Microsift JRE is installed on the machine. (this isn't installed
in Win XP per default)
- The .jar file is located somewhere in the trustlib path.
To implement a facade to the java class (not tested/compiled):
using System.Reflection;
using System.Runtime.InteropServices;
public class SomeJavaClassFacade {
private Type type = typeof(object);
private object javaObject;
public SomeJavaClassFacade() {
javaObject =
Marshall.BindToMoniker("java:full.class.name.in.jar.file");
}
public void someJavaMethod(object someParam) {
type.InvokeMember("javaMethodName", BindingFlags.InvokeMethod,
null, javaObject, new object[] {someParam});
}
}
Another easy way to use a java class in .NET is to use the IKVM, and
binary convert the java .class (or jar) file to a .NET managed assembly.
I've succesfully tried accomplished this too.
see:
http://www.ikvm.net/
/B.invoking