3

We have a major body of code in Java that runs on the desktop that we want to reuse with a MS.NET user interface (desktop rather than web). Any do's or don'ts would be very welcome.

Yishai
  • 90,445
  • 31
  • 189
  • 263
  • The cost of migrating this code is too high (money, time, etc.)? A big issue I see is that you'll need to have both a .NET runtime and a JVM installed in the client system, and I would rather prefer to avoid that situation. – Abel Morelos Nov 16 '09 at 15:16
  • Yes migrating would be well down the list. Point taken regarding 2 runtimes - sounds like a translator is the way to avoid that.. – Chris Chedgey - Structure101 Nov 16 '09 at 16:00
  • Dupe. http://stackoverflow.com/questions/171717/using-java-classes-with-c – finnw Nov 16 '09 at 16:19
  • You could also code the UI in Java, that won't force lock-in to a single OS for your product. – NVRAM Nov 16 '09 at 17:02

5 Answers5

8

You may want to take a look at IKVM.

It is an implementation of the Java Virtual Machine on top of the .NET Framework. There are some parts dealing specifically with interoperability of the .NET and Java worlds so you can (more or less) seamlessly use one from the other.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • Thanks Johannes, IKVN is on our list alright - if you have used it, did you find the bytecode to CLR reliable? – Chris Chedgey - Structure101 Nov 16 '09 at 15:27
  • Haven't used it yet, unfortunately. It's on my personal Todo list to play with it. But apparently they did have some success even with larger Java projects so it appears to be quite mature already, even though AWT/Swing support and security are lacking currently. – Joey Nov 16 '09 at 17:17
6

I suggest creating web services for existing java code to act as a wrapper and call them from .net app. (desktop or web)

SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78
2

If you have the $$$$ you can try mainsoft; it converts your java code in C#, or vice versa, depending on your whim.

Eric Sink has a post about this.

Graviton
  • 81,782
  • 146
  • 424
  • 602
1

Another possible solution could in the the form of j-interop

I've used it successfully for calling from Java -> DCOM and it claims to be able to do bi-directional stuff so in theory it should be possible to register a Java process as a DCOM server.

You will need to do a bit of work on the java side as it won't be able to just make it work automatically.

Gareth Davis
  • 27,701
  • 12
  • 73
  • 106
1

I agree with the webservices method suggested by "2009MIPS". It offers the cleanest and most "debuggable" way to do it.

coolest_head
  • 1,388
  • 1
  • 7
  • 6