Java Properties Load from File loadLibrarySmart(String libraryName)

Here you can find the source of loadLibrarySmart(String libraryName)

Description

load Library Smart

License

Open Source License

Declaration

public static void loadLibrarySmart(String libraryName) 

Method Source Code

//package com.java2s;
/*//from  w  w w.j ava2 s . c  o  m
 * Copyright (c) 2011-2016, Peter Abeles. All Rights Reserved.
 *
 * This file is part of BoofCV (http://boofcv.org).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.*;

public class Main {
    public static void loadLibrarySmart(String libraryName) {

        // see if it works the first try
        if (loadLibrary(libraryName))
            return;

        // otherwise search through the classpath for the library
        String classPath = System.getProperty("java.class.path");

        String stuff[] = classPath.split(":");

        for (String s : stuff) {
            File f = new File(s);
            if (!f.isDirectory())
                continue;
            f = new File(s + "/" + libraryName);
            if (f.exists()) {
                String libraryPath = System.getProperty("java.library.path");
                libraryPath += ":" + s;
                System.setProperty("java.library.path", libraryPath);
                if (!loadLibrary(libraryName))
                    throw new RuntimeException("Shouldn't have failed to load this time");
                return;
            }

        }

        System.out.println("classPath");
    }

    public static boolean loadLibrary(String libraryName) {
        try {
            System.out.println("tring to load: " + libraryName);
            System.loadLibrary(libraryName);
            return true;
        } catch (UnsatisfiedLinkError e) {
            return false;
        }
    }
}

Related

  1. loadInputAsString(InputStream is)
  2. loadInstallProps()
  3. loadJZ(File file)
  4. loadKeys(String propertiesFileName, InputStream in)
  5. loadLibrary(String libFileName)
  6. loadLocalization(final ZipFile file, final String loc)
  7. loadLocatorInfo(String fileName)
  8. loadLWJGL()
  9. loadManifest(File bundleLocation)