How to invoke java class from .net framework?

  • Thread starter Thread starter Wedde
  • Start date Start date
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 :)
 
Hope it's not too late. You can also use JNBridgePro to do the
interop. The Java code can run in the same process, in a different
process on the same machine, or on a different machine running on the
network. See www.jnbridge.com for more information.

Wayne Citrin
JNBridge, LLC
http://www.jnbridge.com
 
Back
Top