예제 #1
0
  @Override
  public boolean loadLibrary(String libname, boolean ignoreError, ClassLoader cl) {
    try {
      for (Entry<String, String> nativeEntry : platformNativeIndex.entrySet()) {
        if (nativeEntry.getKey().contains(libname)) {
          if (log.isDebugEnabled()) {
            log.debug(
                "Loading mapped entry: [{}] [{}] [{}]",
                libname,
                nativeEntry.getKey(),
                nativeEntry.getValue());
          }
          File nativeLibCopy =
              extractJarEntry(
                  nativeEntry.getValue(),
                  nativeEntry.getKey(),
                  System.getProperty(JAVA_TMP_DIR),
                  String.format("%s.jni", libname));
          System.load(nativeLibCopy.getAbsolutePath());
          return true;
        }
      }
    } catch (Exception e) {
      log.error("Unable to load native library [{}] - {}", libname, e);
    }

    if (log.isDebugEnabled()) {
      log.debug("No mapped library match for [{}]", libname);
    }
    return false;
  }
예제 #2
0
  /**
   * Read the version information from a file with a given file name. The file must be a jar
   * manifest file and all its entries are searched for package names and their specification
   * version information. All information is collected in a map for later lookup of package names
   * and their versions.
   *
   * @param versionFileName name of the jar file containing version information
   */
  public static String readVersionFromFile(String applicationName, String versionFileName) {
    try {
      FileInputStream fileInput = new FileInputStream(versionFileName);
      Manifest manifest = new Manifest();
      manifest.read(fileInput);

      Map entries = manifest.getEntries();
      // Now write out the pre-entry attributes
      Iterator entryIterator = entries.entrySet().iterator();
      while (entryIterator.hasNext()) {
        Map.Entry currentEntry = (Map.Entry) entryIterator.next();
        String packageName = currentEntry.getKey().toString();
        packageName = normalizePackageName(packageName);
        Attributes attributes = (Attributes) currentEntry.getValue();
        String packageSpecVersion = attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
        packageSpecVersion = extractVersionInfo(packageSpecVersion);
        return packageSpecVersion;
      }
    } catch (IOException exception) {
      exception.printStackTrace();
    }

    // no version found
    return null;
  }