org.sapia.util
Class ApplicationStarter

java.lang.Object
  extended by org.sapia.util.ApplicationStarter
All Implemented Interfaces:
java.lang.Runnable

public class ApplicationStarter
extends java.lang.Object
implements java.lang.Runnable

The application starter allows to execute the main(String[]) method of a java class from a child classloader of the system classloader. This delegation of the execution of a java class to a child classloader allows an application to be independant in the classes that it loads (because they are not loaded by the system classloader) and give the opportunity to other java application to be loaded by other child classloader of the system classloader without any clash of class name.

The application starter can be called with different options:

Here is two examples of the usage of the application starter. The first example will show the online help message of the application starter and exit. The second example would create a new classloader that would contain the file C:\test.jar as only resource, create a new thread and, from that new thread, call the method main(String[]) on the class MyMainClass passing the two arguments 'foo' and 'bar'.

Finally the application starter can be called programmatically using the start method.

Author:
Jean-Cedric Desrochers
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site

Constructor Summary
protected ApplicationStarter(java.lang.Class aMainClass, java.lang.String[] someArguments)
          Creates a new ApplicationStarter with the passed in arguments.
 
Method Summary
static void main(java.lang.String[] args)
          Main method of the ApplicationStarter class.
 void run()
          Run method of the Runnable interface that calls the main method of the main class.
static void start(java.lang.String aClasspath, java.lang.String aClassName, java.lang.String[] someArguments, boolean isDebug)
          This start method allow the ApplicationStarter to start a new application programmatically passing in the required arguments.
static void usage()
          Prints out on the standard output the usage of the main method of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplicationStarter

protected ApplicationStarter(java.lang.Class aMainClass,
                             java.lang.String[] someArguments)
Creates a new ApplicationStarter with the passed in arguments.

Parameters:
aMainClass - The class on which to call the main() method.
someArguments - The array of argument to pass to the main class.
Method Detail

main

public static void main(java.lang.String[] args)
Main method of the ApplicationStarter class. It first parses the arguments passed in and then it creates a classloader for the main class to execute. Finally, it starts of a new thread that will call the main(String[]) method of the class.

Parameters:
args - The arguments that define the options of the application starter.

start

public static void start(java.lang.String aClasspath,
                         java.lang.String aClassName,
                         java.lang.String[] someArguments,
                         boolean isDebug)
                  throws ApplicationStarterException
This start method allow the ApplicationStarter to start a new application programmatically passing in the required arguments.

Parameters:
aClasspath - The list of resources that defines the classpath use to start the application. Each resource of the classpath must be seperated by the system path seperator defined by the path.separator system proprety and by the static attribute java.io.File.pathSeparator.
aClassName - The qualified name of the class that contains the main() method to start.
someArguments - The arguments that would be passed to the main() method of the class.
isDebug - Indicates of it start the application in debug mode or not.
Throws:
ApplicationStarterException - If an error occurs while starting the application.

usage

public static void usage()
Prints out on the standard output the usage of the main method of this class.


run

public void run()
Run method of the Runnable interface that calls the main method of the main class.

Specified by:
run in interface java.lang.Runnable


Copyright © 2010 Sapia OSS. All Rights Reserved.