1 /*
2 OctopusClassLoader
3 Copyright (C) 2002-2003 Together
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Lesser General Public License for more details.
12 You should have received a copy of the GNU Lesser General Public
13 License along with this library; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 Loader.java
16 Date: 03.03.2003.
17 @version 2.1 alpha
18 @author:
19 Zoran Milakovic zoran@prozone.co.yu
20 */
21
22
23 package org.webdocwf.util.loader;
24
25 import java.io.*;
26 import java.net.*;
27 import java.lang.reflect.*;
28
29 /***
30 *
31 * OctopusClassLoader add files to System Class Loader
32 * @author Zoran Milakovic
33 * @version 1.0
34 */
35 public class OctopusClassLoader {
36
37 private static final Class[] parameters = new Class[] {URL.class};
38
39 /***
40 * This method add file to System class loader
41 * @param s defines the path to file object (string)
42 * @throws IOException
43 */
44 public static void addFile(String s) throws IOException {
45
46 File f = new File(s);
47
48 addFile(f);
49
50 } //end method
51
52 /***
53 * This method add file to System class loader
54 * @param f defines the file object
55 * @throws IOException
56 */
57 public static void addFile(File f) throws IOException {
58
59 addURL(f.toURL());
60
61 } //end method
62
63
64 /***
65 * This method add file to System class loader
66 * @param u defines the url object
67 * @throws IOException
68 */
69 public static void addURL(URL u) throws IOException {
70
71 URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
72
73 Class sysclass = URLClassLoader.class;
74
75 try {
76
77 Method method = sysclass.getDeclaredMethod("addURL", parameters);
78
79 method.setAccessible(true);
80
81 method.invoke(sysloader, new Object[] {u});
82
83 }
84 catch (Throwable t) {
85
86 t.printStackTrace();
87
88 throw new IOException("Error, could not add URL to system classloader");
89
90 } //end try catch
91
92 } //end method
93
94 } //end class
This page was automatically generated by Maven