Code example for URLClassLoader

Methods: loadClass

0
         *       This class loader 
         * 
         * System class loader will (and must) be the parent. 
         */ 
        ClassLoader finalizerLoader = newLoader(getBaseUrl());
        return finalizerLoader.loadClass(FINALIZER_CLASS_NAME);
      } catch (Exception e) {
        logger.log(Level.WARNING, LOADING_ERROR, e);
        return null; 
      } 
    } 
 
    /** 
     * Gets URL for base of path containing Finalizer.class. 
     */ 
    URL getBaseUrl() throws IOException {
      // Find URL pointing to Finalizer.class file. 
      String finalizerPath = FINALIZER_CLASS_NAME.replace('.', '/') + ".class";
      URL finalizerUrl = getClass().getClassLoader().getResource(finalizerPath);
      if (finalizerUrl == null) {
        throw new FileNotFoundException(finalizerPath);
      } 
 
      // Find URL pointing to base of class path. 
      String urlString = finalizerUrl.toString();
      if (!urlString.endsWith(finalizerPath)) {
        throw new IOException("Unsupported path style: " + urlString);
      } 
      urlString = urlString.substring(0,
          urlString.length() - finalizerPath.length());
      return new URL(finalizerUrl, urlString);
    } 
 
    /** Creates a class loader with the given base URL as its classpath. */ 
    URLClassLoader newLoader(URL base) {
      return new URLClassLoader(new URL[] { base });
    } 
  } 
 
  /** 
   * Loads Finalizer directly using the current class loader. We won't be 
Stop searching for code, let great code find you!  Add Codota to your java IDE