JarClassLoaderpublic class JarClassLoader extends URLClassLoader A class loader for loading jar files, both local and remote. |
Fields Summary |
---|
private URL | url |
Constructors Summary |
---|
public JarClassLoader(URL url)Creates a new JarClassLoader for the specified url.
super(new URL[] { url });
this.url = url;
|
Methods Summary |
---|
public java.lang.String | getMainClassName()Returns the name of the jar file main class, or null if
no "Main-Class" manifest attributes was defined.
URL u = new URL("jar", "", url + "!/");
JarURLConnection uc = (JarURLConnection)u.openConnection();
Attributes attr = uc.getMainAttributes();
return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
| public void | invokeClass(java.lang.String name, java.lang.String[] args)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".
Class c = loadClass(name);
Method m = c.getMethod("main", new Class[] { args.getClass() });
m.setAccessible(true);
int mods = m.getModifiers();
if (m.getReturnType() != void.class || !Modifier.isStatic(mods) ||
!Modifier.isPublic(mods)) {
throw new NoSuchMethodException("main");
}
try {
m.invoke(null, new Object[] { args });
} catch (IllegalAccessException e) {
// This should not happen, as we have disabled access checks
}
|
|