Class Launcher
- java.lang.Object
-
- org.codehaus.plexus.classworlds.launcher.Launcher
-
- Direct Known Subclasses:
Launcher
public class Launcher extends java.lang.ObjectCommand-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'smainmethod from the correct class loaded through the correct classloader.The path to the configuration file is specified using the
classworlds.confsystem property, typically specified using the-Dswitch tojava.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringCLASSWORLDS_CONFprivate intexitCodeprotected java.lang.StringmainClassNameprotected java.lang.StringmainRealmNameprotected java.lang.ClassLoadersystemClassLoaderprotected static java.lang.StringUBERJAR_CONF_DIRprotected ClassWorldworld
-
Constructor Summary
Constructors Constructor Description Launcher()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(java.io.InputStream is)Configure from a file.protected java.lang.reflect.MethodgetEnhancedMainMethod()Retrieve the enhanced main entry method.intgetExitCode()java.lang.Class<?>getMainClass()Retrieve the main entry class.java.lang.StringgetMainClassName()protected java.lang.reflect.MethodgetMainMethod()Retrieve the main entry method.ClassRealmgetMainRealm()Retrieve the main entry realm.java.lang.StringgetMainRealmName()java.lang.ClassLoadergetSystemClassLoader()ClassWorldgetWorld()voidlaunch(java.lang.String[] args)Launch the application.protected voidlaunchEnhanced(java.lang.String[] args)Attempt to launch the application through the enhanced main method.protected voidlaunchStandard(java.lang.String[] args)Attempt to launch the application through the standard main method.static voidmain(java.lang.String[] args)Launch the launcher from the command line.static intmainWithExitCode(java.lang.String[] args)Launch the launcher.voidsetAppMain(java.lang.String mainClassName, java.lang.String mainRealmName)voidsetSystemClassLoader(java.lang.ClassLoader loader)voidsetWorld(ClassWorld world)
-
-
-
Field Detail
-
CLASSWORLDS_CONF
protected static final java.lang.String CLASSWORLDS_CONF
- See Also:
- Constant Field Values
-
UBERJAR_CONF_DIR
protected static final java.lang.String UBERJAR_CONF_DIR
- See Also:
- Constant Field Values
-
systemClassLoader
protected java.lang.ClassLoader systemClassLoader
-
mainClassName
protected java.lang.String mainClassName
-
mainRealmName
protected java.lang.String mainRealmName
-
world
protected ClassWorld world
-
exitCode
private int exitCode
-
-
Method Detail
-
setSystemClassLoader
public void setSystemClassLoader(java.lang.ClassLoader loader)
-
getSystemClassLoader
public java.lang.ClassLoader getSystemClassLoader()
-
getExitCode
public int getExitCode()
-
setAppMain
public void setAppMain(java.lang.String mainClassName, java.lang.String mainRealmName)
-
getMainRealmName
public java.lang.String getMainRealmName()
-
getMainClassName
public java.lang.String getMainClassName()
-
setWorld
public void setWorld(ClassWorld world)
-
getWorld
public ClassWorld getWorld()
-
configure
public void configure(java.io.InputStream is) throws java.io.IOException, ConfigurationException, DuplicateRealmException, NoSuchRealmExceptionConfigure from a file.- Parameters:
is- The config input stream.- Throws:
java.io.IOException- If an error occurs reading the config file.java.net.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 java.lang.Class<?> getMainClass() throws java.lang.ClassNotFoundException, NoSuchRealmExceptionRetrieve the main entry class.- Returns:
- The main entry class.
- Throws:
java.lang.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 java.lang.reflect.Method getEnhancedMainMethod() throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, NoSuchRealmExceptionRetrieve the enhanced main entry method.- Returns:
- The enhanced main entry method.
- Throws:
java.lang.ClassNotFoundException- If the main entry class cannot be found.java.lang.NoSuchMethodException- If the main entry method cannot be found.NoSuchRealmException- If the main entry realm cannot be found.
-
getMainMethod
protected java.lang.reflect.Method getMainMethod() throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, NoSuchRealmExceptionRetrieve the main entry method.- Returns:
- The main entry method.
- Throws:
java.lang.ClassNotFoundException- If the main entry class cannot be found.java.lang.NoSuchMethodException- If the main entry method cannot be found.NoSuchRealmException- If the main entry realm cannot be found.
-
launch
public void launch(java.lang.String[] args) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, NoSuchRealmExceptionLaunch the application.- Parameters:
args- The application args.- Throws:
java.lang.ClassNotFoundException- If the main entry class cannot be found.java.lang.IllegalAccessException- If the method cannot be accessed.java.lang.reflect.InvocationTargetException- If the target of the invokation is invalid.java.lang.NoSuchMethodException- If the main entry method cannot be found.NoSuchRealmException- If the main entry realm cannot be found.
-
launchEnhanced
protected void launchEnhanced(java.lang.String[] args) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, NoSuchRealmExceptionAttempt 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:
java.lang.ClassNotFoundException- If the main entry class cannot be found.java.lang.IllegalAccessException- If the method cannot be accessed.java.lang.reflect.InvocationTargetException- If the target of the invokation is invalid.java.lang.NoSuchMethodException- If the main entry method cannot be found.NoSuchRealmException- If the main entry realm cannot be found.
-
launchStandard
protected void launchStandard(java.lang.String[] args) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, NoSuchRealmExceptionAttempt 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:
java.lang.ClassNotFoundException- If the main entry class cannot be found.java.lang.IllegalAccessException- If the method cannot be accessed.java.lang.reflect.InvocationTargetException- If the target of the invokation is invalid.java.lang.NoSuchMethodException- If the main entry method cannot be found.NoSuchRealmException- If the main entry realm cannot be found.
-
main
public static void main(java.lang.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(java.lang.String[] args) throws java.lang.ExceptionLaunch the launcher.- Parameters:
args- The application command-line arguments.- Returns:
- an integer exit code
- Throws:
java.lang.Exception- If an error occurs.
-
-