To my knowledge, anything that I can do in a command shell, I can do from JNI, JNA or Runtime.getRuntime().exec(String)
. So which to use when?
Is it that JNI/JNA allow me to communicate (interprocess communication, etc.) with a running native application that otherwise couldn't be performed from a command shell? Or is it just that Runtime.getRuntime().exec(String)
is platform-independent, whereas JNI/JNA require you to know the platform your on in order to use them?
In a nutshell,
Runtime.exec
(and it's newer friend ProcessBuilder
) launch new external applications.Since each requires cooperation with the host operating system and an existing native binary (whether it's a library or a runnable program) none of them is platform-indepedent.
None of the three permits communicating with a running external application. To do that you need an inter-process communication mechanism, which can be implemented on top of shared memory, files, pipes, or sockets for example.