NIFs vs Jinterface

You cannot call a Java function from Erlang directly. However, you communicate to a Java process from Erlang through a Port process (the name is confusing). This is a separate process that the Erlang VM spawns locally. You can use something like a fat jar and spawn the port process when your own application starts. However Ports are a bit tricky to work with directly. An alternative is to use the library Exile. Exile provides some great protections that you’d otherwise need to add yourself.

With the Port you can use the JInterface library’s message serialization code to create responses that Erlang can directly decode, or rely on something more ‘modern’ like a protobuf or JSON blob. Ports are flexible.

1 Like