--- a/java/gov/lbl/fastbit/FastBit.java 2017-09-19 16:01:19.996924503 -0400
+++ b/java/gov/lbl/fastbit/FastBit.java 2017-09-19 16:26:50.422027222 -0400
@@ -184,8 +184,52 @@
*/
protected void finalize() {cleanup();}
- static { // load the native FastBit library.
- System.loadLibrary("fastbitjni");
+
+ // Helper to load shared library.
+ static boolean tryLoad(String filename) {
+ try {
+ System.load(filename);
+ } catch (Exception e) {
+ return false;
+ } catch (UnsatisfiedLinkError e) {
+ return false;
+ }
+ return true;
+ }
+
+ // Load the native FastBit library.
+ static {
+ boolean mNativeLibrariesLoaded = false;
+ String os = System.getProperty("os.name");
+ if ((os.equals("Linux"))) {
+ // Check for 64-bit library availability
+ // prior to 32-bit library availability.
+ mNativeLibrariesLoaded =
+ tryLoad("/usr/lib64/fastbit/libfastbitjni.so");
+ if (mNativeLibrariesLoaded) {
+ System.out.println("64-bit fastbit library loaded");
+ } else {
+ // REMINDER: May be trying to run a 32-bit app
+ // on 64-bit platform.
+ mNativeLibrariesLoaded =
+ tryLoad("/usr/lib/fastbit/libfastbitjni.so");
+ if (mNativeLibrariesLoaded) {
+ System.out.println("32-bit fastbit library loaded");
+ } else {
+ System.out.println("FAILED loading fastbit library");
+ System.exit(-1);
+ }
+ }
+ } else {
+ try {
+ System.loadLibrary("fastbitjni");
+ System.out.println("fastbit library loaded");
+ mNativeLibrariesLoaded = true;
+ } catch (Throwable t) {
+ // This is bad news, the program is doomed at this point
+ t.printStackTrace();
+ }
+ }
}
} // class FastBit
/// @}