01: package net.sf.clirr.core.internal;
02:
03: import java.io.File;
04: import java.net.MalformedURLException;
05: import java.net.URL;
06: import java.net.URLClassLoader;
07:
08: /**
09: * Helper class for dealing with ClassLoaders.
10: * @author lk
11: */
12: public final class ClassLoaderUtil {
13:
14: /** prevent instatiation. */
15: private ClassLoaderUtil() {
16: }
17:
18: /**
19: * @param cpEntries
20: * @return
21: */
22: public static ClassLoader createClassLoader(final String[] cpEntries) {
23: final URL[] cpUrls = new URL[cpEntries.length];
24: for (int i = 0; i < cpEntries.length; i++) {
25: String cpEntry = cpEntries[i];
26: File entry = new File(cpEntry);
27: try {
28: URL url = entry.toURL();
29: cpUrls[i] = url;
30: } catch (MalformedURLException ex) {
31: final IllegalArgumentException illegalArgEx = new IllegalArgumentException(
32: "Cannot create classLoader from classpath entry "
33: + entry);
34: ExceptionUtil.initCause(illegalArgEx, ex);
35: throw illegalArgEx;
36: }
37: }
38: final URLClassLoader classPathLoader = new URLClassLoader(
39: cpUrls);
40: return classPathLoader;
41: }
42:
43: }
|