1

I've inherited a project, originally written in C++. Due to implementation requirements, I need to either re-write the project in a JVM based language, like Java or Kotlin, or simply wrap the existing code in a Java or Kotlin (RESTful) API.

The existing code base is also entangled with an very old network simulation framework. I'm therefore leaning heavily towards untangling the simulation framework and wrapping the C++ code using something like JNI and SWIG to implement in a non simulated environment.

I'm wondering if JNI and SWIG are still the best options available?

Any advice will be greatly appreciated!

Iggydv
  • 166
  • 2
  • 12
  • 4
    I wouldn't rewrite the C++, and I'd still go the JNI route. If you have the budget hire a JNI C++ expert contractor for a month as the learning curve is quite steep - you need to use lots of guard-type idioms for object references; strong and weak and what you end up with is perfectly readable C++. I don't like SWIG as you tend to end up with an unsupportable mess. – Bathsheba Jan 22 '20 at 15:36

1 Answers1

3

Wrapping with JNI (or SWIG) requires a clever definition of the API. See a nice explanation here. There exist some C++ frameworks that make JNI operations easier on the C++ side, consider them early, before you get too deeply invested in reference management. From what you write, it may be necessary also to provide some Java interface below the C++ layer, e.g. we use the the Java network APIs on Android, even from C++ code.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307