1 package com.maxiq.tools.jboss;
2
3 import java.io.File;
4 import java.io.FilenameFilter;
5
6 import java.net.URL;
7 import java.net.MalformedURLException;
8
9 import java.net.URLClassLoader;
10
11 /***
12 * Loader for JBoss local classes. Loads from the "client" dir of an
13 * existing JBoss installation. Its parent is the bootstrap loader to avoid
14 * version problems on classes.
15 *
16 * @author <a href="mailto:fvancea@maxiq.com">Florin Vancea</a>
17 */
18
19 public class JBossLibClassLoader extends URLClassLoader {
20
21 /***
22 * Constructor taking a File as the pointer to the JBoss installation.
23 * @param jbClientDir The JBoss "client" subdir.
24 */
25 public JBossLibClassLoader(File jbClientDir) {
26 super(explodeBaseDir(jbClientDir), null);
27 }
28
29 /***
30 * Creates an array of URL's containing all JAR files in a directory.
31 * @return An array of URL's
32 * @param baseDir A File pointing to a directory containing JAR files.
33 */
34 static URL[] explodeBaseDir(File baseDir) {
35 File[] jarSet = baseDir.listFiles(new FilenameFilter(){
36 public boolean accept(File dir, String name) {
37 return name.endsWith(".jar");
38 }
39 }
40 );
41 URL[] retval = new URL[jarSet.length];
42 for (int i = 0; i < jarSet.length; i++) {
43 try {
44 retval[i] = jarSet[i].toURL();
45 } catch (MalformedURLException mfuex) {
46 throw new RuntimeException(
47 "Unexpected error: Cannot convert "
48 + jarSet[i] + " to URL form");
49 }
50 }
51 return retval;
52 }
53
54 }
This page was automatically generated by Maven