Here you can find the source of loadClasses(Collection
private static Set<Class<?>> loadClasses(Collection<String> filenames, String packageName, File outputDir)
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main { private static Set<Class<?>> loadClasses(Collection<String> filenames, String packageName, File outputDir) { Set<Class<?>> classes = new HashSet<Class<?>>(); List<String> fullclassname = new ArrayList<String>(); for (String filename : filenames) { fullclassname.add(packageName + "." + filename); }/*from www. j av a2s . c om*/ try { URLClassLoader cl = new URLClassLoader(new URL[] { outputDir.toURI().toURL() }, Thread.currentThread().getContextClassLoader()); for (String c : fullclassname) { classes.add(cl.loadClass(c)); } Thread.currentThread().setContextClassLoader(cl); return classes; } catch (Exception e) { throw new RuntimeException(e); } } }