org.codehaus.classworlds

Class Launcher

Known Direct Subclasses:
EmbeddedLauncher

public class Launcher
extends java.lang.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: Launcher.java 126 2006-01-12 04:17:51Z $
Author:
bob mcwhirter

Field Summary

protected static String
CLASSWORLDS_CONF
protected static String
UBERJAR_CONF_DIR
protected String
mainClassName
protected String
mainRealmName
protected ClassLoader
systemClassLoader
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)

Field Details

CLASSWORLDS_CONF

protected static final String CLASSWORLDS_CONF

UBERJAR_CONF_DIR

protected static final String UBERJAR_CONF_DIR

mainClassName

protected String mainClassName

mainRealmName

protected String mainRealmName

systemClassLoader

protected ClassLoader systemClassLoader

world

protected ClassWorld world

Constructor Details

Launcher

public Launcher()

Method Details

configure

public void configure(InputStream is)
            throws IOException,
                   MalformedURLException,
                   ConfigurationException,
                   DuplicateRealmException,
                   NoSuchRealmException
Configure from a file.
Parameters:
is - The config input stream.
Throws:
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.

getEnhancedMainMethod

protected Method getEnhancedMainMethod()
            throws ClassNotFoundException,
                   NoSuchMethodException,
                   NoSuchRealmException
Retrieve the enhanced main entry method.
Returns:
The enhanced main entry method.
Throws:
NoSuchRealmException - If the main entry realm cannot be found.

getExitCode

public int getExitCode()

getMainClass

public Class getMainClass()
            throws ClassNotFoundException,
                   NoSuchRealmException
Retrieve the main entry class.
Returns:
The main entry class.
Throws:
NoSuchRealmException - If the specified main entry realm does not exist.

getMainClassName

public String getMainClassName()

getMainMethod

protected Method getMainMethod()
            throws ClassNotFoundException,
                   NoSuchMethodException,
                   NoSuchRealmException
Retrieve the main entry method.
Returns:
The main entry method.
Throws:
NoSuchRealmException - If the main entry realm cannot be found.

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.

getMainRealmName

public String getMainRealmName()

getSystemClassLoader

public ClassLoader getSystemClassLoader()

getWorld

public ClassWorld getWorld()

launch

public void launch(String[] args)
            throws ClassNotFoundException,
                   IllegalAccessException,
                   InvocationTargetException,
                   NoSuchMethodException,
                   NoSuchRealmException
Launch the application.
Parameters:
args - The application args.
Throws:
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:
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:
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

setAppMain

public void setAppMain(String mainClassName,
                       String mainRealmName)

setSystemClassLoader

public void setSystemClassLoader(ClassLoader loader)

setWorld

public void setWorld(ClassWorld world)