tags:

views:

2176

answers:

6

I have a project written in Java (>1.5).

Is it possible to write parts of the project with C#?
For instance the GUI and calling the methods and instanciate the classes written in java?

If yes, how?

+6  A: 

Not without something like ikvm - or using web services etc to communicate between the two sides. Basically it's likely to be much more work than either rewriting your existing project code in C# or writing the GUI in Java.

Jon Skeet
Can you explain why it's not possible with dll approach ? Rewriting is an option for small project rewriting 100.000 line for example might be costly ...
Ilya
You'd need to be running both the CLR and the JVM - and the two VMs don't know about each other's objects.
Jon Skeet
You mean, Ilya's answer is not working?
Burkhard
Ilya's answer only applies if you're using the Excelsior JET JRE, and only up to v3.7.
Jon Skeet
I edited my answer to avoid confusion.
Ilya
+4  A: 

There is something called Java Language Conversion Assistant for .NET. You can convert your Java classes to c# and start coding.

There is also something called JNBridge (not free).

Midhat
+3  A: 

It seems like my solution is very limited. and apply only to specific version of java.

I probably will stay with old good C :) Can't imagine how to work without shared libraries :)

This document explain how to create a dll from java and use it in C code. I'm not C# or java expert but i'm sure that you can load external dll's in C# as well. So not a complete solution but good starting point, IMHO. Generally dll it's a perfect way to mixing languages.

Ilya
Note that that document only applies to a particular JRE, and only up to a particular (fairly old - 2005) version.
Jon Skeet
Like i mention i'm not a java expert. Does it mean that that creating dll in java is not trivial ? How one share libraries in java ?
Ilya
Ilya: Java libraries are shared in JAR-files. They are essentially compressed archives (zip I believe) that contain the Java bytecode compiled files and other resources.
Spoike
Ok i get it, Java is not designed to be used by other languages.
Ilya
+1  A: 

In simple way you can pack your java classes to jar file then In C# use Process class for execute and map IO stream

Fuangwith S.
A: 

I did some research on this a few years ago (2005 I believe) and I liked JNBridgePro as the best third party product to do this. Check it out here http://www.jnbridge.com/

Good luck!

+3  A: 

I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.

Pavel Savara