FileDocCategorySizeDatePackage
JavaRunnerURL.javaAPI DocExample3416Sun Oct 25 18:13:34 GMT 1998None

JavaRunnerURL

public class JavaRunnerURL extends Object implements Runnable

Fields Summary
static final int
numArgs
ClassLoader
cl
String
className
Object[]
args
Constructors Summary
JavaRunnerURL(ClassLoader cl, String className, Object[] args)


	      
	    this.cl = cl;
	    this.className = className;
	    this.args = args;
	
Methods Summary
static java.lang.Object[]getArgs(java.lang.String[] args)

		String passArgs[] = new String[args.length - numArgs];
		for (int i = numArgs; i < args.length; i++)
			passArgs[i - numArgs] = args[i];

		Object wrapArgs[] = new Object[1];
		wrapArgs[0] = passArgs;
		return wrapArgs;
	
voidinvokeMain(java.lang.Class clazz)

		Class argList[] = new Class[1];
		String strArray[] = new String[1];
		argList[0] = strArray.getClass();
		Method mainMethod = null;
		try {
			mainMethod = clazz.getMethod("main", argList);
		} catch (NoSuchMethodException nsme) {
			System.out.println("No main method in " + clazz.getName());
			System.exit(-1);
		}
	
		try {
			mainMethod.invoke(null, args);
		} catch (Throwable e) {
			e.printStackTrace();
			if (e instanceof InvocationTargetException)
				e = ((InvocationTargetException) e)
							.getTargetException();
			System.out.println("Procedure exited with exception " + e);
			e.printStackTrace();
		}
	
public static voidmain(java.lang.String[] args)

		URL urls[] = new URL[2];
		try {
			urls[0] = new URL(args[0]);
			urls[1] = new URL(args[1]);
		} catch (Exception mue) {
			System.err.println("Bad URL specification");
		}
		Class self = JavaRunnerURL.class;
		URLClassLoader ucl = new URLClassLoader(urls, self.getClassLoader());
		ThreadGroup tg = new ThreadGroup("JavaRunner Threadgroup");
		Thread t = new Thread(tg,
				new JavaRunnerURL(ucl, args[2], getArgs(args)));
		t.start();
		try {
			t.join();
		} catch (InterruptedException ie) {
			System.out.println("Thread was interrupted");
		}
	
public voidrun()

		Class target = null;
		try {
			target = cl.loadClass(className);
			invokeMain(target);
		} catch (ClassNotFoundException cnfe) {
			System.out.println("Can't load " + className);
			cnfe.printStackTrace();
		}