org.codehaus.plexus.classworlds.launcher

Class 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 StringCLASSWORLDS_CONF
intexitCode
protected StringmainClassName
protected StringmainRealmName
protected ClassLoadersystemClassLoader
protected static StringUBERJAR_CONF_DIR
protected ClassWorldworld
Constructor Summary
Launcher()
Method Summary
voidconfigure(InputStream is)
Configure from a file.
protected MethodgetEnhancedMainMethod()
Retrieve the enhanced main entry method.
intgetExitCode()
ClassgetMainClass()
Retrieve the main entry class.
StringgetMainClassName()
protected MethodgetMainMethod()
Retrieve the main entry method.
ClassRealmgetMainRealm()
Retrieve the main entry realm.
StringgetMainRealmName()
ClassLoadergetSystemClassLoader()
ClassWorldgetWorld()
voidlaunch(String[] args)
Launch the application.
protected voidlaunchEnhanced(String[] args)
Attempt to launch the application through the enhanced main method.
protected voidlaunchStandard(String[] args)
Attempt to launch the application through the standard main method.
static voidmain(String[] args)
Launch the launcher from the command line.
static intmainWithExitCode(String[] args)
Launch the launcher.
voidsetAppMain(String mainClassName, String mainRealmName)
voidsetSystemClassLoader(ClassLoader loader)
voidsetWorld(ClassWorld world)

Field Detail

CLASSWORLDS_CONF

protected static final String CLASSWORLDS_CONF

exitCode

private int exitCode

mainClassName

protected String mainClassName

mainRealmName

protected String mainRealmName

systemClassLoader

protected ClassLoader systemClassLoader

UBERJAR_CONF_DIR

protected static final String UBERJAR_CONF_DIR

world

protected ClassWorld world

Constructor Detail

Launcher

public Launcher()

Method Detail

configure

public void configure(InputStream is)
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. org.codehaus.plexus.classworlds.realm.DuplicateRealmException If the config file defines two realms with the same id. org.codehaus.plexus.classworlds.realm.NoSuchRealmException If the config file defines a main entry point in a non-existent realm.

getEnhancedMainMethod

protected Method getEnhancedMainMethod()
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.

getExitCode

public int getExitCode()

getMainClass

public Class getMainClass()
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.

getMainClassName

public String getMainClassName()

getMainMethod

protected Method getMainMethod()
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.

getMainRealm

public ClassRealm getMainRealm()
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)
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)
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)
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)
Launch the launcher.

Parameters: args The application command-line arguments.

Returns: an integer exit code

Throws: Exception If an error occurs.

setAppMain

public void setAppMain(String mainClassName, String mainRealmName)

setSystemClassLoader

public void setSystemClassLoader(ClassLoader loader)

setWorld

public void setWorld(ClassWorld world)