Class Launcher

java.lang.Object
org.springframework.boot.loader.Launcher
Direct Known Subclasses:
ExecutableArchiveLauncher, PropertiesLauncher

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.
Since:
1.0.0
Author:
Phillip Webb, Dave Syer
  • Constructor Details

    • Launcher

      public Launcher()
  • Method Details

    • launch

      protected void launch(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(Iterator<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
      Since:
      2.3.0
    • 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 void launch(String[] args, String launchClass, ClassLoader classLoader) throws Exception
      Launch the application given the archive file and a fully configured classloader.
      Parameters:
      args - the incoming arguments
      launchClass - the launch class to run
      classLoader - the classloader
      Throws:
      Exception - if the launch fails
    • createMainMethodRunner

      protected MainMethodRunner createMainMethodRunner(String mainClass, 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
    • getClassPathArchivesIterator

      protected abstract Iterator<Archive> getClassPathArchivesIterator() 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
      Since:
      2.3.0
    • createArchive

      protected final Archive createArchive() throws Exception
      Throws:
      Exception
    • isExploded

      protected boolean isExploded()
      Returns if the launcher is running in an exploded mode. If this method returns true then only regular JARs are supported and the additional URL and ClassLoader support infrastructure can be optimized.
      Returns:
      if the jar is exploded.
      Since:
      2.3.0
    • getArchive

      protected Archive getArchive()
      Return the root archive.
      Returns:
      the root archive
      Since:
      2.3.1