jni4net
bridge between Java and .NET (intraprocess, fast, object oriented, open-source)
How to use
How it works
Using reflection we grab public method signatures for core classes of .NET and Java and generated proxy classes for the other side.
We have .NET version of
JNI API.
We use JNI to forward the call from
.NET proxies to methods on real Java objects.
(explanation)
We use JNI to register .NET implementation of native methods of
Java proxies to forward call to methods on real .NET objects.
(explanation)
Features
- Intraprocess - it means that both VMs are in same process. Any call uses same thread and same stack for both environments. It's relatively fast.
- Proxies - we use proxies which look like and behave like the real/original object. Marshaled by reference except for primitive types and arrays.
- Garbage collected - if you don't create cycle between VMs heaps, the proxies and instances are collected and released properly.
- Proxygen - tool to wrap your own library. Works with reflection, so you need just .jar or .dll, and proxygen config file. You could wrap most CLR or JVM classes.
- Core - core classes of JDK and .NET framework are already included in jni4net. Using that for reflection and invocation across the boundary is possible.
- Samples - are included with the binaries. See ReadMe.md in directories
- Troubleshooting - use knowledge base or Stackoverflow or ask people
- Platforms - at the moment only Windows 32 and 64 bits. CLR 2.0 and CLR 4.0. JRE 1.5 and above.
- License - opensource, GPL tools and MIT runtime
- Status - Runtime is currently stable with ocasional bug fix. The proxygen is ugly, but I don't have enough time to rewrite it. I tried in branch 0.9
- Contact - use mailing group or talk to pavel.savara@gmail.com
using net.sf.jni4net;
public class Program
{
private static void Main()
{
Bridge.CreateJVM(new BridgeSetup());
java.lang.System.@out.println("Greetings from C# to Java world!");
}
}
import net.sf.jni4net.Bridge;
import java.io.IOException;
import java.lang.String;
public class Program {
public static void main(String[] args) throws IOException {
Bridge.init();
system.Console.WriteLine("Greetings from Java to .NET world!");
}
}