org.codehaus.plexus.classworlds.launcher
Class Launcher

java.lang.Object
  extended by org.codehaus.plexus.classworlds.launcher.Launcher
Direct Known Subclasses:
Launcher

public class Launcher
extends Object

Command-line invokable application launcher.

This launcher class assists in the creation of classloaders and ClassRealms from a configuration file and the launching of the application's main method from the correct class loaded through the correct classloader.

The path to the configuration file is specified using the classworlds.conf system property, typically specified using the -D switch to java.

Version:
$Id$
Author:
bob mcwhirter

Field Summary
protected static String CLASSWORLDS_CONF
           
protected  String mainClassName
           
protected  String mainRealmName
           
protected  ClassLoader systemClassLoader
           
protected static String UBERJAR_CONF_DIR
           
protected  ClassWorld world
           
 
Constructor Summary
Launcher()
           
 
Method Summary
 void configure(InputStream is)
          Configure from a file.
protected  Method getEnhancedMainMethod()
          Retrieve the enhanced main entry method.
 int getExitCode()
           
 Class getMainClass()
          Retrieve the main entry class.
 String getMainClassName()
           
protected  Method getMainMethod()
          Retrieve the main entry method.
 ClassRealm getMainRealm()
          Retrieve the main entry realm.
 String getMainRealmName()
           
 ClassLoader getSystemClassLoader()
           
 ClassWorld getWorld()
           
 void launch(String[] args)
          Launch the application.
protected  void launchEnhanced(String[] args)
          Attempt to launch the application through the enhanced main method.
protected  void launchStandard(String[] args)
          Attempt to launch the application through the standard main method.
static void main(String[] args)
          Launch the launcher from the command line.
static int mainWithExitCode(String[] args)
          Launch the launcher.
 void setAppMain(String mainClassName, String mainRealmName)
           
 void setSystemClassLoader(ClassLoader loader)
           
 void setWorld(ClassWorld world)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSWORLDS_CONF

protected static final String CLASSWORLDS_CONF
See Also:
Constant Field Values

UBERJAR_CONF_DIR

protected static final String UBERJAR_CONF_DIR
See Also:
Constant Field Values

systemClassLoader

protected ClassLoader systemClassLoader

mainClassName

protected String mainClassName

mainRealmName

protected String mainRealmName

world

protected ClassWorld world
Constructor Detail

Launcher

public Launcher()
Method Detail

setSystemClassLoader

public void setSystemClassLoader(ClassLoader loader)

getSystemClassLoader

public ClassLoader getSystemClassLoader()

getExitCode

public int getExitCode()

setAppMain

public void setAppMain(String mainClassName,
                       String mainRealmName)

getMainRealmName

public String getMainRealmName()

getMainClassName

public String getMainClassName()

setWorld

public void setWorld(ClassWorld world)

getWorld

public ClassWorld getWorld()

configure

public void configure(InputStream is)
               throws IOException,
                      ConfigurationException,
                      DuplicateRealmException,
                      NoSuchRealmException
Configure from a file.

Parameters:
is - The config input stream.
Throws:
IOException - If an error occurs reading the config file.
MalformedURLException - If the config file contains invalid URLs.
ConfigurationException - If the config file is corrupt.
DuplicateRealmException - If the config file defines two realms with the same id.
NoSuchRealmException - If the config file defines a main entry point in a non-existent realm.

getMainClass

public Class getMainClass()
                   throws ClassNotFoundException,
                          NoSuchRealmException
Retrieve the main entry class.

Returns:
The main entry class.
Throws:
ClassNotFoundException - If the class cannot be found.
NoSuchRealmException - If the specified main entry realm does not exist.

getMainRealm

public ClassRealm getMainRealm()
                        throws NoSuchRealmException
Retrieve the main entry realm.

Returns:
The main entry realm.
Throws:
NoSuchRealmException - If the specified main entry realm does not exist.

getEnhancedMainMethod

protected Method getEnhancedMainMethod()
                                throws ClassNotFoundException,
                                       NoSuchMethodException,
                                       NoSuchRealmException
Retrieve the enhanced main entry method.

Returns:
The enhanced main entry method.
Throws:
ClassNotFoundException - If the main entry class cannot be found.
NoSuchMethodException - If the main entry method cannot be found.
NoSuchRealmException - If the main entry realm cannot be found.

getMainMethod

protected Method getMainMethod()
                        throws ClassNotFoundException,
                               NoSuchMethodException,
                               NoSuchRealmException
Retrieve the main entry method.

Returns:
The main entry method.
Throws:
ClassNotFoundException - If the main entry class cannot be found.
NoSuchMethodException - If the main entry method cannot be found.
NoSuchRealmException - If the main entry realm cannot be found.

launch

public void launch(String[] args)
            throws ClassNotFoundException,
                   IllegalAccessException,
                   InvocationTargetException,
                   NoSuchMethodException,
                   NoSuchRealmException
Launch the application.

Parameters:
args - The application args.
Throws:
ClassNotFoundException - If the main entry class cannot be found.
IllegalAccessException - If the method cannot be accessed.
InvocationTargetException - If the target of the invokation is invalid.
NoSuchMethodException - If the main entry method cannot be found.
NoSuchRealmException - If the main entry realm cannot be found.

launchEnhanced

protected void launchEnhanced(String[] args)
                       throws ClassNotFoundException,
                              IllegalAccessException,
                              InvocationTargetException,
                              NoSuchMethodException,
                              NoSuchRealmException
Attempt to launch the application through the enhanced main method.

This will seek a method with the exact signature of:

  public static void main(String[] args, ClassWorld world)
  

Parameters:
args - The application args.
Throws:
ClassNotFoundException - If the main entry class cannot be found.
IllegalAccessException - If the method cannot be accessed.
InvocationTargetException - If the target of the invokation is invalid.
NoSuchMethodException - If the main entry method cannot be found.
NoSuchRealmException - If the main entry realm cannot be found.

launchStandard

protected void launchStandard(String[] args)
                       throws ClassNotFoundException,
                              IllegalAccessException,
                              InvocationTargetException,
                              NoSuchMethodException,
                              NoSuchRealmException
Attempt to launch the application through the standard main method.

This will seek a method with the exact signature of:

  public static void main(String[] args)
  

Parameters:
args - The application args.
Throws:
ClassNotFoundException - If the main entry class cannot be found.
IllegalAccessException - If the method cannot be accessed.
InvocationTargetException - If the target of the invokation is invalid.
NoSuchMethodException - If the main entry method cannot be found.
NoSuchRealmException - If the main entry realm cannot be found.

main

public static void main(String[] args)
Launch the launcher from the command line. Will exit using System.exit with an exit code of 0 for success, 100 if there was an unknown exception, or some other code for an application error.

Parameters:
args - The application command-line arguments.

mainWithExitCode

public static int mainWithExitCode(String[] args)
                            throws Exception
Launch the launcher.

Parameters:
args - The application command-line arguments.
Returns:
an integer exit code
Throws:
Exception - If an error occurs.


Copyright © 2002-2012 Codehaus. All Rights Reserved.