Here you can find the source of getClassLoaderForDirectory(final File baseFolder)
private static ClassLoader getClassLoaderForDirectory(final File baseFolder) throws MalformedURLException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; public class Main { private static final ReadWriteLock LOCK = new ReentrantReadWriteLock(); private static final Map<File, ClassLoader> CLASSLOADER_MAP = new ConcurrentHashMap<>(16); private static ClassLoader getClassLoaderForDirectory(final File baseFolder) throws MalformedURLException { final Lock readLock = LOCK.readLock(); readLock.lock();//from www . ja va 2 s . c om if (CLASSLOADER_MAP.containsKey(baseFolder)) { readLock.unlock(); return CLASSLOADER_MAP.get(baseFolder); } else { final Lock writeLock = LOCK.writeLock(); writeLock.lock(); try { final URLClassLoader classLoader = URLClassLoader .newInstance(new URL[] { baseFolder.toURI().toURL() }); CLASSLOADER_MAP.put(baseFolder, classLoader); return classLoader; } finally { writeLock.unlock(); } } } }