Here you can find the source of loadClass(final File baseFolder, final String qualifiedType)
public static Class<?> loadClass(final File baseFolder, final String qualifiedType)
//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); public static Class<?> loadClass(final File baseFolder, final String qualifiedType) { try {//from ww w . j a v a2 s . c o m return getClassLoaderForDirectory(baseFolder).loadClass(qualifiedType); } catch (ClassNotFoundException | MalformedURLException e) { throw new IllegalStateException(e); } } private static ClassLoader getClassLoaderForDirectory(final File baseFolder) throws MalformedURLException { final Lock readLock = LOCK.readLock(); readLock.lock(); 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(); } } } }