示例#1
0
    // Adds referenced classpath elements from a jar's Class-Path
    // Manifest entry.  In some future release, we may want to
    // update this code to recognize URLs rather than simple
    // filenames, but if we do, we should redo all path-related code.
    private void addJarClassPath(String jarFileName, boolean warn) {
      try {
        String jarParent = new File(jarFileName).getParent();
        JarFile jar = new JarFile(jarFileName);

        try {
          Manifest man = jar.getManifest();
          if (man == null) return;

          Attributes attr = man.getMainAttributes();
          if (attr == null) return;

          String path = attr.getValue(Attributes.Name.CLASS_PATH);
          if (path == null) return;

          for (StringTokenizer st = new StringTokenizer(path); st.hasMoreTokens(); ) {
            String elt = st.nextToken();
            if (jarParent != null) elt = new File(jarParent, elt).getCanonicalPath();
            addFile(elt, warn);
          }
        } finally {
          jar.close();
        }
      } catch (IOException e) {
        //              log.error(Position.NOPOS,
        //                        "error.reading.file", jarFileName,
        //                        e.getLocalizedMessage());
      }
    }
示例#2
0
  protected static URL[] getUrlArray(String codebase) throws MalformedURLException {
    // Parse codebase into separate URLs
    StringTokenizer parser = new StringTokenizer(codebase);
    Vector<String> vec = new Vector<>(10);
    while (parser.hasMoreTokens()) {
      vec.addElement(parser.nextToken());
    }
    String[] url = new String[vec.size()];
    for (int i = 0; i < url.length; i++) {
      url[i] = vec.elementAt(i);
    }

    URL[] urlArray = new URL[url.length];
    for (int i = 0; i < urlArray.length; i++) {
      urlArray[i] = new URL(url[i]);
    }
    return urlArray;
  }