KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > starter > JiveClassLoader


1 /**
2  * $RCSfile: JiveClassLoader.java,v $
3  * $Revision: 1.4 $
4  * $Date: 2005/03/07 05:36:27 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.messenger.starter;
13
14 import java.io.File JavaDoc;
15 import java.io.FilenameFilter JavaDoc;
16 import java.net.MalformedURLException JavaDoc;
17 import java.net.URL JavaDoc;
18 import java.net.URLClassLoader JavaDoc;
19
20 /**
21  * A simple classloader to extend the classpath to
22  * include all jars in a lib directory.<p>
23  *
24  * The new classpath includes all <tt>*.jar</tt> and <tt>*.zip</tt>
25  * archives (zip is commonly used in packaging JDBC drivers). The extended
26  * classpath is used for both the initial server startup, as well as loading
27  * plug-in support jars.
28  *
29  * @author Derek DeMoro
30  * @author Iain Shigeoka
31  */

32 class JiveClassLoader extends URLClassLoader JavaDoc {
33
34     /**
35      * Constructs the classloader.
36      *
37      * @param parent the parent class loader (or null for none).
38      * @param libDir the directory to load jar files from.
39      * @throws java.net.MalformedURLException if the libDir path is not valid.
40      */

41     JiveClassLoader(ClassLoader JavaDoc parent, File JavaDoc libDir) throws MalformedURLException JavaDoc {
42         super(new URL JavaDoc[] { libDir.toURL() }, parent);
43
44         File JavaDoc[] jars = libDir.listFiles(new FilenameFilter JavaDoc() {
45             public boolean accept(File JavaDoc dir, String JavaDoc name) {
46                 boolean accept = false;
47                 String JavaDoc smallName = name.toLowerCase();
48                 if (smallName.endsWith(".jar")) {
49                     accept = true;
50                 }
51                 else if (smallName.endsWith(".zip")) {
52                     accept = true;
53                 }
54                 return accept;
55             }
56         });
57
58         // Do nothing if no jar or zip files were found
59
if (jars == null) {
60             return;
61         }
62
63         for (int i = 0; i < jars.length; i++) {
64             if (jars[i].isFile()) {
65                 addURL(jars[i].toURL());
66             }
67         }
68     }
69 }
70
Popular Tags