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 ClassRealm
s
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
Modifier and TypeFieldDescriptionprotected static final String
protected String
protected String
protected ClassLoader
protected static final String
protected ClassWorld
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(InputStream is) Configure from a file.protected Method
Retrieve the enhanced main entry method.int
Class
<?> Retrieve the main entry class.protected Method
Retrieve the main entry method.Retrieve the main entry realm.getWorld()
void
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
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
- 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
Launch the launcher.- Parameters:
args
- The application command-line arguments.- Returns:
- an integer exit code
- Throws:
Exception
- If an error occurs.
-