public static void removeFromClassPath(String[] pathsToRemove) throws IOException {
    Thread curThread = Thread.currentThread();
    ClassLoader currentLoader = curThread.getContextClassLoader();
    // If current class loader is NOT UDFClassLoader, then it is a system class loader, we should not mess with it.
    if (!(currentLoader instanceof UDFClassLoader)) {
      LOG.warn("Ignoring attempt to manipulate {}; probably means we have closed more UDF loaders than opened.",
          currentLoader == null ? "null" : currentLoader.getClass().getSimpleName());
      return;
    }
    // Otherwise -- for UDFClassLoaders -- we close the current one and create a new one, with more limited class path.

    UDFClassLoader loader = (UDFClassLoader) currentLoader;

    Set<URL> newPath = new HashSet<URL>(Arrays.asList(loader.getURLs()));

    for (String onestr : pathsToRemove) {
      URL oneurl = urlFromPathString(onestr);
      if (oneurl != null) {
        newPath.remove(oneurl);
      }
    }
    JavaUtils.closeClassLoader(loader);
    // This loader is closed, remove it from cached registry loaders to avoid removing it again.
    Registry reg = SessionState.getRegistry();
    if (reg != null) {
      reg.removeFromUDFLoaders(loader);
    }

    loader = new UDFClassLoader(newPath.toArray(new URL[0]));
    curThread.setContextClassLoader(loader);
    SessionState.get().getConf().setClassLoader(loader);
  }
Remove elements from the classpath, if possible. This will only work if the current thread context class loader is
an UDFClassLoader (i.e. if we have created it).

@param pathsToRemove
         Array of classpath elements
ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java