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