You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2009/10/21 16:41:58 UTC

svn commit: r828035 - /incubator/uima/uimaj/trunk/uimaj-bootstrap/src/main/java/org/apache/uima/bootstrap/UimaBootstrap.java

Author: schor
Date: Wed Oct 21 14:41:57 2009
New Revision: 828035

URL: http://svn.apache.org/viewvc?rev=828035&view=rev
Log:
UIMA-1631

Modified:
    incubator/uima/uimaj/trunk/uimaj-bootstrap/src/main/java/org/apache/uima/bootstrap/UimaBootstrap.java

Modified: incubator/uima/uimaj/trunk/uimaj-bootstrap/src/main/java/org/apache/uima/bootstrap/UimaBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-bootstrap/src/main/java/org/apache/uima/bootstrap/UimaBootstrap.java?rev=828035&r1=828034&r2=828035&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-bootstrap/src/main/java/org/apache/uima/bootstrap/UimaBootstrap.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-bootstrap/src/main/java/org/apache/uima/bootstrap/UimaBootstrap.java Wed Oct 21 14:41:57 2009
@@ -80,12 +80,13 @@
     }    
     suppressClassPathDisplay = System.getProperty("UimaBootstrapSuppressClassPathDisplay") != null;
     URL[] urls = getUrls();
-    URLClassLoader cl = new ParentFirstWithResourceClassLoader(urls);
-    Thread.currentThread().setContextClassLoader(cl);
+//    URLClassLoader cl = new ParentFirstWithResourceClassLoader(urls);
+//    Thread.currentThread().setContextClassLoader(cl);
+    addUrlsToSystemLoader(urls);
     
     Class<?> classToLaunch = null;
     try {
-      classToLaunch = cl.loadClass(args[0]);
+      classToLaunch = ClassLoader.getSystemClassLoader().loadClass(args[0]);
     } catch (ClassNotFoundException e) {
      System.err.println("Cannot find class to launch");
      System.exit(1);
@@ -147,50 +148,65 @@
     urls.add(url);
   }
 
-  private static class ParentFirstWithResourceClassLoader extends URLClassLoader {
- 
-    /**
-     * Creates a new ParentFirstWithResourceClassLoader 
-     * 
-     * @param urls
-     *          an array of URLs representing JAR files
-     * 
-     * @throws MalformedURLException
-     *           if a malformed URL has occurred in the classpath string.
-     */
-    public ParentFirstWithResourceClassLoader(URL[] urls) {
-      super(urls);
-    }
-
-
-    @SuppressWarnings("unchecked")
-    protected synchronized Class loadClass(String name, boolean resolve)
-            throws ClassNotFoundException {
-      // First, check if the class has already been loaded
-      Class c = findLoadedClass(name);
-      if (c == null) {
-        // delegate class loading for class
-        try {
-          c = super.loadClass(name, false);
-        } catch (ClassNotFoundException e) {
-          // try to load class
-          c = findClass(name);
-        }
-      }
-      if (resolve) {
-        resolveClass(c);
-      }
-      return c;
-    }
-
-    // make sure resources are looked up first in this loader
-    // ASSUMES that getResourceAsStream calls getResource
-//    @Override
-//    public URL getResource(String resName) {
-//      URL r = findResource(resName);
-//      if (r != null) 
-//        return r;
-//      return super.getResource(resName);  
-//    }    
-  } 
+  private static void addUrlsToSystemLoader(URL[] urls) throws IOException {
+    URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
+    try {
+       Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
+       method.setAccessible(true); // is normally "protected"
+       for (URL url : urls) {
+         method.invoke(systemClassLoader, new Object[]{url});
+       }
+    } catch (Throwable t) {
+       t.printStackTrace();
+       throw new IOException("Error, could not add URL to system classloader");
+    } 
+  }
+  
+  
+//  private static class ParentFirstWithResourceClassLoader extends URLClassLoader {
+// 
+//    /**
+//     * Creates a new ParentFirstWithResourceClassLoader 
+//     * 
+//     * @param urls
+//     *          an array of URLs representing JAR files
+//     * 
+//     * @throws MalformedURLException
+//     *           if a malformed URL has occurred in the classpath string.
+//     */
+//    public ParentFirstWithResourceClassLoader(URL[] urls) {
+//      super(urls);
+//    }
+//
+//
+//    @SuppressWarnings("unchecked")
+//    protected synchronized Class loadClass(String name, boolean resolve)
+//            throws ClassNotFoundException {
+//      // First, check if the class has already been loaded
+//      Class c = findLoadedClass(name);
+//      if (c == null) {
+//        // delegate class loading for class
+//        try {
+//          c = super.loadClass(name, false);
+//        } catch (ClassNotFoundException e) {
+//          // try to load class
+//          c = findClass(name);
+//        }
+//      }
+//      if (resolve) {
+//        resolveClass(c);
+//      }
+//      return c;
+//    }
+//
+//    // make sure resources are looked up first in this loader
+//    // ASSUMES that getResourceAsStream calls getResource
+////    @Override
+////    public URL getResource(String resName) {
+////      URL r = findResource(resName);
+////      if (r != null) 
+////        return r;
+////      return super.getResource(resName);  
+////    }    
+//  } 
 }