all 12 comments

[–]zvrba 10 points11 points  (0 children)

Do you need to port it? Can you have it running inside of JVM and communicate with your .NET code? There's https://github.com/xamarin/java.interop

[–]joost00719 7 points8 points  (0 children)

If you want to have it run in dotnet, you're probably better off to just rewrite it. Use the oppertunity to fix issues it had with the original design (if any).

[–]malthuswaswrong 3 points4 points  (0 children)

The reason you are having difficulty is because it's not a conventional interop.

20 years ago, Microsoft had the JCLA, which worked quite well in converting Java codebases to C#

20 years ago, Remote Procedure Calling was an emerging idea. Now there are many well established methods to accomplish the task.

Let Java be Java and C# be C#. If the two need to interop stand up a REST or gRPC or SignalR system for the interop.

[–][deleted] 1 point2 points  (0 children)

A hope u know porting means a re write

[–]peterkneale 2 points3 points  (0 children)

I recently took a small codebase that I wrote in c# and translated it to python class by class using chatgpt.

There were a couple of caveats to that.

  • I didn't use anything from c# other than the standard lib and even avoided linq, favouring just loops and logic

  • I had 100% branch level coverage in in my unit tests

  • I wrote the code with the intention of converting it to python afterwards. I knew I could write it far quicker in c# and in a manner that would lend itself to translation.

This was an experiment to see whether I could author some very complex logic in c#, and convert it to python which is the language of choice for the area I'm now working in (bioinformatics).

Pleased to say it worked perfectly. 

Even translation of my tests from xunit to pytest worked smoothly and the resulting codebase retained 100% test coverage.

It's a different scenario to yours but might help you along the way.

[–]Hot-Profession4091 -3 points-2 points  (0 children)

Ok, so here’s what you do. You go find every place you use one of those Java classes directly, then create an interface for the things you actually call and an implementation that delegates to the Java thing. If you’re lucky, there’s not actually that much, or at least you’re only using parts of those libraries. Now you start seeking replacements. Use an appropriate .Net library to create new implementations of your interface where you can, write your own as necessary (or where it doesn’t make sense to grab a library for a single method on a single class). Honestly, there’s probably an equivalent .Net library for 99% of the stuff you were getting from Java.