public static ClassLoader createClassLoader(File[] unpacked,
File[] packed,
URL[] urls,
ClassLoader parent) throws Exception {
if (log.isDebugEnabled())
log.debug("Creating new class loader");
// Construct the "class path" for this class loader
ArrayList list = new ArrayList();
// Add unpacked directories
if (unpacked != null) {
for (int i = 0; i < unpacked.length; i++) {
File file = unpacked[i];
if (!file.exists() || !file.canRead())
continue;
file = new File(file.getCanonicalPath() + File.separator);
URL url = file.toURL();
if (log.isDebugEnabled())
log.debug(" Including directory " + url);
list.add(url);
}
}
// Add packed directory JAR files
if (packed != null) {
for (int i = 0; i < packed.length; i++) {
File directory = packed[i];
if (!directory.isDirectory() || !directory.exists() ||
!directory.canRead())
continue;
String filenames[] = directory.list();
for (int j = 0; j < filenames.length; j++) {
String filename = filenames[j].toLowerCase();
if (!filename.endsWith(".jar"))
continue;
File file = new File(directory, filenames[j]);
if (log.isDebugEnabled())
log.debug(" Including jar file " + file.getAbsolutePath());
URL url = file.toURL();
list.add(url);
}
}
}
// Construct the class loader itself
URL[] array = (URL[]) list.toArray(new URL[list.size()]);
StandardClassLoader classLoader = null;
if (parent == null)
classLoader = new StandardClassLoader(array);
else
classLoader = new StandardClassLoader(array, parent);
return (classLoader);
}
Create and return a new class loader, based on the configuration
defaults and the specified directory paths: |