test/sun/misc/ClassLoaderUtil/Test.java

Print this page




  42             fos.write (buf, 0, c);
  43         }
  44         fis.close();
  45         fos.close();
  46         return dest;
  47     }
  48 
  49     public static void main(String[] args) throws Exception {
  50         String srcPath = System.getProperty("test.src");
  51         String destPath = System.getProperty("test.classes");
  52         if (destPath == null || "".equals(destPath)) {
  53             throw new RuntimeException ("Not running test");
  54         }
  55         File file = new File (srcPath, "test.jar");
  56         file = copy (file, destPath);
  57         URL url = file.toURL();
  58         URLClassLoader loader = new URLClassLoader (new URL [] {url});
  59         Class clazz = Class.forName ("Foo", true,  loader);
  60         Object obj = clazz.newInstance();
  61         List<String> jarsclosed = new LinkedList<String>();
  62         sun.misc.ClassLoaderUtil.releaseLoader (loader, jarsclosed);
  63         for (String jar: jarsclosed) {
  64             System.out.println ("Successfully closed " + jar);
  65         }
  66         if (!file.delete()) {
  67             throw new RuntimeException ("failed to delete jar file");
  68         }
  69     }
  70 }


  42             fos.write (buf, 0, c);
  43         }
  44         fis.close();
  45         fos.close();
  46         return dest;
  47     }
  48 
  49     public static void main(String[] args) throws Exception {
  50         String srcPath = System.getProperty("test.src");
  51         String destPath = System.getProperty("test.classes");
  52         if (destPath == null || "".equals(destPath)) {
  53             throw new RuntimeException ("Not running test");
  54         }
  55         File file = new File (srcPath, "test.jar");
  56         file = copy (file, destPath);
  57         URL url = file.toURL();
  58         URLClassLoader loader = new URLClassLoader (new URL [] {url});
  59         Class clazz = Class.forName ("Foo", true,  loader);
  60         Object obj = clazz.newInstance();
  61         List<String> jarsclosed = new LinkedList<String>();
  62         // OLD API sun.misc.ClassLoaderUtil.releaseLoader (loader, jarsclosed);
  63         loader.close();


  64         if (!file.delete()) {
  65             throw new RuntimeException ("failed to delete jar file");
  66         }
  67     }
  68 }