java/hybridse-sdk/src/main/java/com/_4paradigm/hybridse/LibraryLoader.java
public static synchronized void loadLibrary(String libraryPath) {
        logger.info("Try to load the library {}", libraryPath);

        boolean isPath = libraryPath.endsWith(".so") || libraryPath.endsWith(".dylib");
        if (!isPath) {
            // try load from environment
            try {
                System.loadLibrary(libraryPath);
                logger.info("Successfully load library {}", libraryPath);
                return;
            } catch (Throwable t) {
                logger.debug(String.format("Failed to load %s", libraryPath), t);
            }
        }
        if (!isPath) {
            String osName = System.getProperty("os.name").toLowerCase();
            if (osName.equals("mac os x")) {
                libraryPath = "lib" + libraryPath + ".dylib";
            } else if (osName.contains("linux")) {
                libraryPath = "lib" + libraryPath + ".so";
            } else {
                throw new IllegalArgumentException("Do not support os type: " + osName);
            }
        }

        // load from local filesystem
        try {
            System.load(libraryPath);
            logger.info("Successfully load library from {}", libraryPath);
            return;
        } catch (Throwable t) {
            logger.debug(String.format("Failed to load from %s", libraryPath), t);
        }

        // load from resource
        logger.info("Can not find {} from environment, try find in resources", libraryPath);
        try {
            URL resource = LibraryLoader.class.getClassLoader().getResource(libraryPath);
            if (resource != null) {
                try {
                    System.load(resource.getPath());
                } catch (UnsatisfiedLinkError e) {
                    // maybe extract out of jar
                    String localPath = extractResource(libraryPath, true);
                    logger.info("Extract resource to {}", localPath);
                    System.load(localPath);
                }
                logger.info("Successfully load {} in local resource", resource.getPath());
            } else {
                logger.error(String.format("Fail to find %s in resources", libraryPath));
            }
        } catch (IOException | UnsatisfiedLinkError e) {
            logger.error(String.format("Error while load %s from local resource", libraryPath), e);
            e.printStackTrace();
            throw new UnsatisfiedLinkError(String.format("Fail to load library %s", libraryPath));
        }
    }
/**
     * Firstly attempts to load the native library specified by the libraryPath.
     * If that fails then it falls back to extracting the library from the classpath.
     *
     * @param libraryPath library path
     */
Firstly attempts to load the native library specified by the libraryPath.
If that fails then it falls back to extracting the library from the classpath.

@param libraryPath library path
Firstly attempts to load the native library specified by the libraryPath . If that fails then it falls back to extracting the library from the classpath . @param libraryPath library path
public static synchronized void loadLibrary(String libraryPath) {
        logger.info("Try to load the library {}", libraryPath);
        boolean isPath = libraryPath.endsWith(".so") || libraryPath.endsWith(".dylib");
        if (!isPath) {
            try {
                System.loadLibrary(libraryPath);
                logger.info("Successfully load library {}", libraryPath);
                return;
            } catch (Throwable t) {
                logger.debug(String.format("Failed to load %s", libraryPath), t);
            }
        }
        if (!isPath) {
            String osName = System.getProperty("os.name").toLowerCase();
            if (osName.equals("mac os x")) {
                libraryPath = "lib" + libraryPath + ".dylib";
            } else if (osName.contains("linux")) {
                libraryPath = "lib" + libraryPath + ".so";
            } else {
                throw new IllegalArgumentException("Do not support os type: " + osName);
            }
        }
        try {
            System.load(libraryPath);
            logger.info("Successfully load library from {}", libraryPath);
            return;
        } catch (Throwable t) {
            logger.debug(String.format("Failed to load from %s", libraryPath), t);
        }
        logger.info("Can not find {} from environment, try find in resources", libraryPath);
        try {
            URL resource = LibraryLoader.class.getClassLoader().getResource(libraryPath);
            if (resource != null) {
                try {
                    System.load(resource.getPath());
                } catch (UnsatisfiedLinkError e) {
                    String localPath = extractResource(libraryPath, true);
                    logger.info("Extract resource to {}", localPath);
                    System.load(localPath);
                }
                logger.info("Successfully load {} in local resource", resource.getPath());
            } else {
                logger.error(String.format("Fail to find %s in resources", libraryPath));
            }
        } catch (IOException | UnsatisfiedLinkError e) {
            logger.error(String.format("Error while load %s from local resource", libraryPath), e);
            e.printStackTrace();
            throw new UnsatisfiedLinkError(String.format("Fail to load library %s", libraryPath));
        }
    }
public static synchronized void loadLibrary ( String libraryPath ) { logger . info ( "Try to load the library {}" , libraryPath ) ; boolean isPath = libraryPath . endsWith ( ".so" ) || libraryPath . endsWith ( ".dylib" ) ; if ( ! isPath ) { try { System . loadLibrary ( libraryPath ) ; logger . info ( "Successfully load library {}" , libraryPath ) ; return ; } catch ( Throwable t ) { logger . debug ( String . format ( "Failed to load %s" , libraryPath ) , t ) ; } } if ( ! isPath ) { String osName = System . getProperty ( "os.name" ) . toLowerCase ( ) ; if ( osName . equals ( "mac os x" ) ) { libraryPath = "lib" + libraryPath + ".dylib" ; } else if ( osName . contains ( "linux" ) ) { libraryPath = "lib" + libraryPath + ".so" ; } else { throw new IllegalArgumentException ( "Do not support os type: " + osName ) ; } } try { System . load ( libraryPath ) ; logger . info ( "Successfully load library from {}" , libraryPath ) ; return ; } catch ( Throwable t ) { logger . debug ( String . format ( "Failed to load from %s" , libraryPath ) , t ) ; } logger . info ( "Can not find {} from environment, try find in resources" , libraryPath ) ; try { URL resource = LibraryLoader . class . getClassLoader ( ) . getResource ( libraryPath ) ; if ( resource != null ) { try { System . load ( resource . getPath ( ) ) ; } catch ( UnsatisfiedLinkError e ) { String localPath = extractResource ( libraryPath , true ) ; logger . info ( "Extract resource to {}" , localPath ) ; System . load ( localPath ) ; } logger . info ( "Successfully load {} in local resource" , resource . getPath ( ) ) ; } else { logger . error ( String . format ( "Fail to find %s in resources" , libraryPath ) ) ; } } catch ( IOException | UnsatisfiedLinkError e ) { logger . error ( String . format ( "Error while load %s from local resource" , libraryPath ) , e ) ; e . printStackTrace ( ) ; throw new UnsatisfiedLinkError ( String . format ( "Fail to load library %s" , libraryPath ) ) ; } }
Firstly attempts to load the native library specified by the libraryPath.
Firstly attempts to load the native library specified by the libraryPath .
// try load from environment // load from local filesystem // load from resource // maybe extract out of jar