Parsing Engine

danbikel.util
Class JarClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by danbikel.util.JarClassLoader

public class JarClassLoader
extends URLClassLoader

A class loader for loading a jar file from any URL. Modified from a version taken from Sun's Java website (The JarClassLoader Class).


Constructor Summary
JarClassLoader(URL url)
          Creates a new JarClassLoader for the specified URL.
JarClassLoader(URL url, ClassLoader parent)
          Creates a new JarClassLoader for the specified URL and parent class loader.
 
Method Summary
 String getMainClassName()
          Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
 void invokeClass(String name, String[] args)
          Invokes the application in this jar file given the name of the main class and an array of arguments.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JarClassLoader

public JarClassLoader(URL url)
Creates a new JarClassLoader for the specified URL.

Parameters:
url - the url of the jar file

JarClassLoader

public JarClassLoader(URL url,
                      ClassLoader parent)
Creates a new JarClassLoader for the specified URL and parent class loader.

Parameters:
url - the url of the jar file
parent - the parent class loader for delegation
Method Detail

getMainClassName

public String getMainClassName()
                        throws IOException
Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.

Throws:
IOException

invokeClass

public void invokeClass(String name,
                        String[] args)
                 throws ClassNotFoundException,
                        NoSuchMethodException,
                        InvocationTargetException
Invokes the application in this jar file given the name of the main class and an array of arguments. The class must define a static method "main" which takes an array of String arguemtns and is of return type "void".

Parameters:
name - the name of the main class
args - the arguments for the application
Throws:
ClassNotFoundException - if the specified class could not be found
NoSuchMethodException - if the specified class does not contain a "main" method
InvocationTargetException - if the application raised an exception

Parsing Engine

Author: Dan Bikel.