1 45 46 package org.openejb.loader; 47 48 import java.net.URLClassLoader ; 49 import java.net.URL ; 50 import java.io.File ; 51 52 55 56 57 58 public class SystemClassPath extends BasicURLClassPath { 59 60 private URLClassLoader sysLoader; 61 62 public void addJarsToPath(File dir) throws Exception { 63 this.addJarsToPath(dir, getSystemLoader()); 64 this.rebuildJavaClassPathVariable(); 65 } 66 67 public void addJarToPath(URL jar) throws Exception { 68 this.addJarToPath(jar, getSystemLoader()); 70 this.rebuildJavaClassPathVariable(); 71 } 72 73 public ClassLoader getClassLoader() { 74 try { 75 return getSystemLoader(); 76 } catch (Exception e) { 77 throw new RuntimeException (e); 78 } 79 } 80 81 private URLClassLoader getSystemLoader() throws Exception { 82 if (sysLoader == null) { 83 sysLoader = (URLClassLoader ) ClassLoader.getSystemClassLoader(); 84 } 85 return sysLoader; 86 } 87 88 private void rebuildJavaClassPathVariable() throws Exception { 89 sun.misc.URLClassPath cp = getURLClassPath(getSystemLoader()); 90 URL [] urls = cp.getURLs(); 91 if (urls.length < 1) 95 return; 96 97 StringBuffer path = new StringBuffer (urls.length * 32); 98 99 File s = new File (urls[0].getFile()); 100 path.append(s.getPath()); 101 103 for (int i = 1; i < urls.length; i++) { 104 path.append(File.pathSeparator); 105 106 s = new File (urls[i].getFile()); 107 path.append(s.getPath()); 109 } 110 try { 111 System.setProperty("java.class.path", path.toString()); 112 } catch (Exception e) { 113 } 114 } 115 } 116 | Popular Tags |