Access a JAR outside the CLASSPATH

From CodeCodex

Implementations[edit]

Java[edit]

import java.net.*;
import java.io.*;

public class ExtraLoader {

  public static void main(String[] args) {
    try {
     URL urlA = 
        new File("C:/xtras/xercesImpl.jar").toURL();
     URL urlB = 
        new File("C:/xtras/xmlParserAPIs.jar").toURL();
     URL[] urls = { urlA,urlB };
     URLClassLoader ulc = new URLClassLoader(urls);
     //
     Class c = Class.forName
        ("org.apache.xerces.dom.ChildNode", true, ulc);
     //
     System.out.println(c.getName());
    }
    catch(Exception e) {
     e.printStackTrace();
    }
  }
}

--------------------------------------------------------------------------------