I am using jni4net to access Java code from a C # application and vice versa. jni4net uses reflection to generate the proxy code for the JNI code, so obviously one of the limitations is that your Java and C # code must be compiled to create the proxy.
Unfortunately, this can lead to a catch-22 problem. Consider:
C # class X uses Java Y class
Java class Y uses C # X class
None of them can be compiled, so a well-established solution is to take one of the classes (X or Y), break it into your bare signature and force it to compile, and then generate a proxy from the compiled skeleton. Then you can replace the divided class with the original and continue your fun journey.
This seems like an ugly approach to me, and I believe that there should be a better way. The obvious solution would be to tell the compiler (either C # or Java, it doesn't really matter) to ignore references to the missing class.
Do not ignore references to some missing class valid for C # or Java compilers? Is there a better way to do this (and no, I'm not open to considering sockets or anything of that nature, I need a real transition between .NET and Java)?
An example code was requested:
The jni4net transition code example code has been removed for clarity. IA and IB simple interfaces are also not included.
Java:
public class A implements IA { public void m1() { System.out.println("m1 called"); } public static void main (String args[]) { IB b = new B(); b.m2(new A()); } }
FROM#:
public class B : IB { public void m2(IA a) { a.m1(); A a2 = new A(); a2.m1(); } }
source share