Class Launcher
java.lang.Object
org.codehaus.plexus.classworlds.launcher.Launcher
- Direct Known Subclasses:
Launcher
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.
- Author:
- bob mcwhirter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected Stringprotected Stringprotected ClassLoaderprotected static final Stringprotected ClassWorld -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(InputStream is) Configure from a file.protected MethodRetrieve the enhanced main entry method.intClass<?> Retrieve the main entry class.protected MethodRetrieve the main entry method.Retrieve the main entry realm.getWorld()voidLaunch 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 voidLaunch 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 Details
-
CLASSWORLDS_CONF
- See Also:
-
UBERJAR_CONF_DIR
- See Also:
-
systemClassLoader
-
mainClassName
-
mainRealmName
-
world
-
-
Constructor Details
-
Launcher
public Launcher()
-
-
Method Details
-
setSystemClassLoader
-
getSystemClassLoader
-
getExitCode
public int getExitCode() -
setAppMain
-
getMainRealmName
-
getMainClassName
-
setWorld
-
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
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
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, NoSuchRealmExceptionRetrieve 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, NoSuchRealmExceptionRetrieve 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
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
-