How to use JNI, but only when available for current platform?

Posted by Mecki on Stack Overflow See other posts from Stack Overflow or by Mecki
Published on 2010-03-12T10:23:09Z Indexed on 2010/03/12 10:27 UTC
Read the original article Hit count: 200

Filed under:
|

What is the common way (or best practice) to optionally use JNI?

E.g. I have a Java class and this class is 100% pure Java, so it can run on all platforms. However, on some platforms I'd like to speed up some heavy calculations using JNI - which works fine. Unfortunately I cannot support any existing Java platform in the world. So I guess it is fine to initially only support the big three: Linux, Windows, Mac OS X.

So what I'd like to do is to use JNI on those three platforms and use the 100% pure Java version on all other platforms. Now I can think of various ways how to do that (loading class dynamically for example and either loading the JNI class or the pure Java one), but thinking that this is a common issue that thousands of projects had to solve in the past for sure, I'm really surprised to not find any documentation or references to the question how to solve this most elegantly or effectively.

© Stack Overflow or respective owner

Related posts about java

Related posts about jni