-1

I'm aware of all the other questions about this topic, but I haven't found a good solution for my problem. Currently I am trying to use Java code in my C# project. I've already tried to convert the JAR files into .DLL files with IKVM, but this didn't work for me because the JAR files are to complicated to translate into C# because not every component, which were used in Java, can be found in C#. The normal call of the JAR file doesn't work for me either because I need to work with the class instances of the declared classes in the Java code.

Back to my question: Does anybody know how I could use Java code in my project? I've heard that it may be possible to implement Java code like it would be native, is that true? Note that I've to work with the class instances of the classes declared in the Java code.

I highly appreciate any kind of help, sheers!


Edit: My work around would be that I include batch files, which are calling the JAR files. I will include these batch files into my C# Project and work with the batch files. This may be a even better approach for me because every input and output of the JAR files are done via XML files.

MD. RAKIB HASAN
  • 3,670
  • 4
  • 22
  • 35
Maik Hasler
  • 1,064
  • 6
  • 36
  • If the usual interop approaches aren't working for you, is it not possible to rewrite the Java library in C#? – ProgrammingLlama Nov 10 '21 at 06:41
  • @Llama I also thought about that, but that would be too much work, since they get updated twice a year and are very big. It would take to long to translate – Maik Hasler Nov 10 '21 at 06:51

1 Answers1

1

This kind of mixup are not generally a good approach. I think the .Net Framework is very mature and you can find everything you want to do your work.

I would suggest you the following approach :

  1. You can wrap your Java library in a REST API and call it in your C# code. Your REST API can be hosted on an external server or use an embedded server or even a spring boot project.
  2. You can read this post for more details.
Harry Coder
  • 2,429
  • 2
  • 28
  • 32