tags:

views:

283

answers:

3

I've got a medium sized (25k lines code, 25k lines tests) codebase in java, and would like to port it to run on a CLR as well as the JVM.

Only the main class, and a few testing utilities deal with the file system or OS in any way. The rest of the code uses the generic collections APIs extensively, java.util.regex, java.net (but not URL or URLConnection), java.io for charset encoding/decoding, java.text for unicode normalization, and org.w3c.dom for XML manipulation.

Is it possible to get most of the codebase compiling under both J# and Java, and then port the rest?

If so, what kind of pitfalls am I likely to run into?

thanks in advance, mike

+3  A: 

Pitfalls:

  • Anything like this scares the heck out of me. The number of really subtle bugs waiting to happen is huge.
  • J# only supports Java 1.1.4 AFAIK - goodbye generics etc.
  • Visual Studio 2008 doesn't support J# - basically it's a dead project.

I suspect that you'd actually find it simpler to rewrite it in C# (including learning C# if you don't already know it - it's a joy). You'll end up with a more idiomatically .NET-like library that way as well, if that's relevant: if you ever want another .NET developer to consume your code, they're likely to be far happier with a "pure" .NET project than one using J#.

The downside is that going forward, any changes would also need to be made in two places. There's certainly pain there, but I really think you'll have a better experience using "normal" .NET.

Jon Skeet
+5  A: 

Check out IKVM: http://www.ikvm.net/

It allows you to run (specially compiled) Java code inside the .Net CLR.

Some of my colleages have used it successfully with a Java codebase of 1 million+ lines of code.

PeterR
darn, you where faster ;-)
Joachim Sauer
I was searching for this even before Jon Skeet posted his answer. But my Google skills are in sorry shape today. (Try searching for "compile java to clr", then change it to "compile java to .net". I didn't have the magic word.) But +1 for actually having experience with it.
Michael Myers
Why didn't I think of this? Depending on *why* the OP wants to run in the CLR, this might be exactly the ticket.
Jon Skeet
+2  A: 

As Jon pointed out: J# is pretty dead.

Running your (normal) Java code on .NET using IKVM might be an alternative, 'though.

Joachim Sauer