Class Launcher

  • Direct Known Subclasses:
    ExecutableArchiveLauncher

    public abstract class Launcher
    extends Object
    Base class for launchers that can start an application with a fully configured classpath backed by one or more Archives.
    Author:
    Phillip Webb, Dave Syer
    • Constructor Detail

      • Launcher

        public Launcher()
    • Method Detail

      • launch

        protected Object launch​(String method,
                                String[] args)
                         throws Exception
        Launch the application. This method is the initial entry point that should be called by a subclass public static void main(String[] args) method.
        Parameters:
        args - the incoming arguments
        Throws:
        Exception - if the application fails to launch
      • createClassLoader

        protected ClassLoader createClassLoader​(List<Archive> archives)
                                         throws Exception
        Create a classloader for the specified archives.
        Parameters:
        archives - the archives
        Returns:
        the classloader
        Throws:
        Exception - if the classloader cannot be created
      • createClassLoader

        protected ClassLoader createClassLoader​(URL[] urls)
                                         throws Exception
        Create a classloader for the specified URLs.
        Parameters:
        urls - the URLs
        Returns:
        the classloader
        Throws:
        Exception - if the classloader cannot be created
      • launch

        protected Object launch​(String method,
                                String[] args,
                                String mainClass,
                                ClassLoader classLoader)
                         throws Exception
        Launch the application given the archive file and a fully configured classloader.
        Parameters:
        args - the incoming arguments
        mainClass - the main class to run
        classLoader - the classloader
        Throws:
        Exception - if the launch fails
      • createMainMethodRunner

        protected MainMethodRunner createMainMethodRunner​(String mainClass,
                                                          String method,
                                                          String[] args,
                                                          ClassLoader classLoader)
        Create the MainMethodRunner used to launch the application.
        Parameters:
        mainClass - the main class
        args - the incoming arguments
        classLoader - the classloader
        Returns:
        the main method runner
      • getMainClass

        protected abstract String getMainClass()
                                        throws Exception
        Returns the main class that should be launched.
        Returns:
        the name of the main class
        Throws:
        Exception - if the main class cannot be obtained
      • getClassPathArchives

        protected abstract List<Archive> getClassPathArchives()
                                                       throws Exception
        Returns the archives that will be used to construct the class path.
        Returns:
        the class path archives
        Throws:
        Exception - if the class path archives cannot be obtained