4

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 instantiate the classes written in java?

If yes, how?

ItamarG3
  • 4,092
  • 6
  • 31
  • 44
Burkhard
  • 14,596
  • 22
  • 87
  • 108

6 Answers6

19

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
  • 3,427
  • 1
  • 30
  • 35
8

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194
6

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).

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
Midhat
  • 17,454
  • 22
  • 87
  • 114
4

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
  • 3,104
  • 3
  • 23
  • 30
  • Note that that document only applies to a particular JRE, and only up to a particular (fairly old - 2005) version. – Jon Skeet Oct 06 '08 at 09:43
  • 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 Oct 15 '08 at 07:38
  • 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 Oct 15 '08 at 07:48
2

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.
  • 5,654
  • 8
  • 37
  • 41
0

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!