Class Launcher

java.lang.Object
org.springframework.boot.loader.launch.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.
Since:
3.2.0
Author:
Phillip Webb, Dave Syer, Scott Frederick
  • Field Details

    • BOOT_CLASSPATH_INDEX_ATTRIBUTE

      protected static final String BOOT_CLASSPATH_INDEX_ATTRIBUTE
      See Also:
    • DEFAULT_CLASSPATH_INDEX_FILE_NAME

      protected static final String DEFAULT_CLASSPATH_INDEX_FILE_NAME
      See Also:
    • classPathIndex

      protected org.springframework.boot.loader.launch.ClassPathIndexFile classPathIndex
  • 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(Collection<URL> urls) throws Exception
      Create a classloader for the specified archives.
      Parameters:
      urls - the classpath URLs
      Returns:
      the classloader
      Throws:
      Exception - if the classloader cannot be created
    • launch

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

      protected abstract Archive getArchive()
      Return the archive being launched or null if there is no archive.
      Returns:
      the launched archive
    • 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
    • getClassPathUrls

      protected abstract Set<URL> getClassPathUrls() 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
    • getEntryPathPrefix

      protected String getEntryPathPrefix()
      Return the path prefix for relevant entries in the archive.
      Returns:
      the entry path prefix
    • isIncludedOnClassPath

      protected boolean isIncludedOnClassPath(Archive.Entry entry)
      Determine if the specified entry is a nested item that should be added to the classpath.
      Parameters:
      entry - the entry to check
      Returns:
      true if the entry is a nested item (jar or directory)
    • isLibraryFileOrClassesDirectory

      protected boolean isLibraryFileOrClassesDirectory(Archive.Entry entry)
    • isIncludedOnClassPathAndNotIndexed

      protected boolean isIncludedOnClassPathAndNotIndexed(Archive.Entry entry)