views:

53

answers:

2

Is it possible to call CLR methods from JVM? Any library that would host a CLR instance inside JVM, and provide a simple mapping for Java? Are there any libraries that would do that?

I'd like to write a plugin for existing Java application which already runs on JVM.

I'd like to avoid having two binaries. I only want to call few methods in an existing .NET assembly (MSBuild-related Microsoft.Build.Framework.* stuff).

+1  A: 

Natively no this is not possible. The Java and CLR virtual machines are very different beasts that do not natively support each others byte code set.

It is possible though to use third party libraries to bridge the two techonologies together. Here are a few (more available via google)

JaredPar
I would think you could do it with COM somehow.
Gabe
@Gabe, I'm sure COM would work as well. Both .Net and Java support calling out to COM objects so it could certainly be a bridge techonology.
JaredPar
@Gabe: I have never used COM. Does the CLR assembly need to do anything special to expose interfaces, or maybe it is possible to call arbitrary methods using it?
liori
Yes this is indeed a good idea. See http://www.simple-talk.com/content/print.aspx?article=276 for exposing a COM assembly. And then take a look at https://com4j.dev.java.net/ for accessing COM components from Java.
renick
+1  A: 

There are two different ways to do this. You can run Java on the CLR using IKVM. Conversely you can embed Mono which is a .NET CLR implementation, although this will require using C and JNI.
All these assume that you can comply with the terms the open source licenses.

renick