Example usage for java.net URLClassLoader close

List of usage examples for java.net URLClassLoader close

Introduction

In this page you can find the example usage for java.net URLClassLoader close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this URLClassLoader, so that it can no longer be used to load new classes or resources that are defined by this loader.

Usage

From source file:org.microtitan.diffusive.utils.ClassLoaderUtils.java

public static void main(String[] args) throws IOException {
    // set the logging level
    DOMConfigurator.configure("log4j.xml");
    Logger.getRootLogger().setLevel(Level.DEBUG);

    final String classname = "org.microtitan.tests.threaded.MultiThreadedCalc";
    final byte[] systemBytes = loadClassToByteArray(classname);
    if (systemBytes == null) {
        System.out.println("null");
    } else {/*from w  w w  .j  a v  a  2 s.c  o m*/
        System.out.println(systemBytes.length);
    }

    final URL url = new URL("file", null,
            "///C:/Users/desktop/workspace/diffusive/Diffusive_v0.2.0/examples/example_0.2.0.jar");
    //      final URL url = new URL( "file", null, "/Users/rob/Documents/workspace/diffusive/Diffusive_v0.2.0/examples/example_0.2.0.jar" );
    System.out.println(url.toString());
    final URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { url });
    final byte[] urlBytes = loadClassToByteArray(classname, urlClassLoader);
    if (urlBytes == null) {
        System.out.println("null");
    } else {
        System.out.println(urlBytes.length);
    }

    final InputStream input = urlClassLoader.getResourceAsStream(classname.replace('.', '/') + ".class");
    if (input == null) {
        System.out.println("null");
    } else {
        System.out.println(IOUtils.toByteArray(input).length);
    }
    urlClassLoader.close();

    //      final String className = BeanTest.class.getName();
    //      byte[] bytes = convertClassToByteArray( className );
    //      
    //      Class< ? > clazz = new RestfulClassLoader( null, ClassLoaderUtils.class.getClassLoader() ).getClazz( className, bytes );
    //      try
    //      {
    //         final Method method = clazz.getMethod( "print" );
    //         method.invoke( clazz.newInstance() );
    //      }
    //      catch( IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException | InstantiationException e )
    //      {
    //         e.printStackTrace();
    //      }
    //      
    //      System.out.println( clazz.getName() );
}