Logger.stderr("Cannot instantiate controller from the given jar " + path);

return null;

} catch (IllegalAccessException e) {

Logger.stderr("You are not authorized to access constructor for " + path);

return null;

} catch (IllegalArgumentException e) {

Logger.stderr("You have passed wrong argument to " + path);

return null;

} catch (InvocationTargetException e) {

Logger.stderr("Wrong invocation target for " + path);

return null;

}

}

}

Above code is from a working system. Basically, all you need to look is the URLClassLoader, loadJar method, and codes that actually call the constructor of the loaded class.

In implementing this class, We have used a utiliy class called 'Basename'. As we set the name of the Jar file to the complete path of the class including package name (for example, xxx.yyy.SimpleClass), the class 'Basename' is critical in extracting the class name that would be instantiated.