Best and simpler way to call .net assemblies in java

Is there a way to call .net assemblies of more specific DLL files in java?

I am developing a framework for .net now i need to port it to java, can i do that? I am using C # in .net.

+2


source to share


3 answers


Check if this answer is helpful. Calling .net build from java jvm crashes ..

Moved through this interesting site (maybe not directly useful to you) ...



dotnetfromjava.dev.java.net

+1


source


The easiest way is to include a .Net COM assembly. This way you can call any method, just as you would communicate with regular WIN32 DLLs.



Some examples can be found here: http://www.devx.com/interop/Article/19845

+2


source


There is no need for COM objects and I would not recommend any custom solutions as it would be like reusing a wheel. There are many specific cases and details about this kind of integration that would arise, for example when passing "ref", "out", generic methods, etc ... the best I would like to suggest is to use JAVA for .NET -bridge, for example www.javonet.com .

Here is a short article on this solution: http://javabridges.hubpages.com/hub/Using-NET-libraries-from-JAVA-is-that-possible

There are other such bridges as well, but with javonet you get a very simple API that with a single JAR file allows you to simply copy your .NET DLL and call it directly without any extra steps. It supports .NET exceptions, object deletion, instance invocation and static methods including generics, setting / getting fields and more ... You work with .NET DLLs in java as they were a native JAVA class.

Usage example:

//Sample Usage of .NET Random Class from JAVA using Javonet
NObject dotNetRandom = Javonet.New("System.Random");
Integer randomNumber = dotNetRandom.invoke("Next",5,10);

      

Note that such a bridge will automatically convert the results to native JAVA types, if possible, and similarly with method arguments. Lots of samples that you can read in the quick start guide on the Javonet website.

+1


source







All Articles