tags:

views:

248

answers:

4

Is there a way using JNI and C# code to create a program that invoke any given Java method? Assume that I have a jar containing classes hierarchy and I'm responsible for loading the JVM and these classes, can I write a C# program that receives the java method signature + arguments values on the fly and call the java code?

Please try to restrict your answers to free technologies (JNI solutions prefered).

Thnks, Guy

+1  A: 

IKVM is one option. It implements a JVM in .Net and provides interop tools.

Marcelo Cantos
How can IKVM helps here, the resolution should be made in runtime and not by creating static artifacts (.NET proxies)?
Guy
@Guy - IKVM can be used in both dynamic and static modes; see http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=User%27s_Guide In dynamic mode, Java bytecodes are translated on the fly into CIL by the class loader.
Stephen C
Being more general, I want to draw away from the solution that creates .NET proxy.
Guy
The dynamic mode is just as calling Java.exe and can be applied on java programs (i.e. with main(String[]) ). Not good for me.
Guy
+2  A: 

IMHO the best way would be to run the Java Program as a WebService (or create a Java based WebService Interface for it) and just call it from C#.

dbemerlin
I didn't mention that I don't have any clue regarding the Java code nor any possibility to change it. The only input I have is:JAR, method name, arguments and values
Guy
A: 

There are bridges available to achieve this.
Check this article: http://www.devx.com/interop/Article/19945/1954

cornerback84
A: 

jni4net is opensource bridge between .NET & Java. Object oriented, fast, based on JNI. Part of the library is C# wrappers for Java reflection.

Pavel Savara