KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > sun > appserv > AppservClassLoader


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AppservClassLoader.java
26  *
27 */

28
29 package org.apache.tools.ant.taskdefs.optional.sun.appserv;
30
31 import java.util.Hashtable JavaDoc;
32 import java.io.File JavaDoc;
33 import java.net.URL JavaDoc;
34 import java.net.URLClassLoader JavaDoc;
35 import java.net.MalformedURLException JavaDoc;
36
37
38 public class AppservClassLoader extends URLClassLoader JavaDoc {
39     private Hashtable JavaDoc hashTable = new Hashtable JavaDoc(3); // small
40

41     /** Creates new AppservClassLoader _mapping is key=value;key=value....*/
42     public AppservClassLoader() throws MalformedURLException JavaDoc, RuntimeException JavaDoc {
43         super(new URL JavaDoc[0], AppservClassLoader.class.getClassLoader());
44     }
45     
46     public void addURL(File JavaDoc f) throws MalformedURLException JavaDoc, RuntimeException JavaDoc {
47             if (f.isFile()){
48                 addURL(f.toURI().toURL());
49               /// System.out.println("adding file = "+f.getAbsolutePath());
50
/// System.out.println("adding file exists= "+f.exists() );
51
}
52             else{
53               /// System.out.println("file does not exist!!! = "+f.getAbsolutePath());
54
}
55     }
56
57
58     public static AppservClassLoader getClassLoader() {
59         
60         AppservClassLoader loader = null;
61
62         try {
63             loader = new AppservClassLoader();
64             String JavaDoc installRoot = System.getProperty("com.sun.aas.installRoot");
65             if (installRoot == null) {
66                     //set installRoot to current directory
67
installRoot = ".";
68             }
69
70             File JavaDoc f;
71             
72             final String JavaDoc classpathPrefix = System.getProperty("com.sun.ant.classpath.prefix");
73             if (classpathPrefix != null) {
74                 f = new File JavaDoc(classpathPrefix);
75                 loader.addURL(f);
76             }
77
78             final String JavaDoc derbyRoot = System.getProperty("derby.root");
79             if (derbyRoot != null) {
80                 //set derby jar file
81
f = new File JavaDoc (derbyRoot+"/lib/derby.jar");
82                 loader.addURL(f);
83             }
84             
85             f = new File JavaDoc(installRoot+"/lib");
86             loader.addURL(f);
87             f = new File JavaDoc(installRoot+"/lib/appserv-ws.jar");
88             loader.addURL(f);
89             f = new File JavaDoc(installRoot+"/lib/appserv-se.jar");
90             loader.addURL(f);
91             f = new File JavaDoc(installRoot+"/lib/appserv-admin.jar");
92             loader.addURL(f);
93             f = new File JavaDoc(installRoot+"/lib/appserv-ext.jar");
94             loader.addURL(f);
95             f = new File JavaDoc(installRoot+"/lib/appserv-rt.jar");
96             loader.addURL(f);
97             f = new File JavaDoc(installRoot+"/lib/appserv-cmp.jar");
98             loader.addURL(f);
99             f = new File JavaDoc(installRoot+"/lib/admin-cli.jar");
100             loader.addURL(f);
101             f = new File JavaDoc(installRoot+"/lib/commons-launcher.jar");
102             loader.addURL(f);
103             f = new File JavaDoc(installRoot+"/lib/javaee.jar");
104             loader.addURL(f);
105             f = new File JavaDoc(installRoot+"/lib/install/applications/jmsra/imqjmsra.jar");
106             loader.addURL(f);
107         }catch (Exception JavaDoc ex) {
108             ex.printStackTrace();
109                 //throw new Exception(ex2.getLocalizedMessage());
110
}
111         return loader;
112     }
113
114 }
115
Popular Tags