org.springframework.boot.loader.tools

Class MainClassFinder



  • public abstract class MainClassFinder
    extends Object
    Finds any class with a public static main method by performing a breadth first search.
    Author:
    Phillip Webb, Andy Wilkinson
    • Constructor Detail

      • MainClassFinder

        public MainClassFinder()
    • Method Detail

      • findMainClass

        public static String findMainClass(File rootFolder)
                                    throws IOException
        Find the main class from a given folder.
        Parameters:
        rootFolder - the root folder to search
        Returns:
        the main class or null
        Throws:
        IOException - if the folder cannot be read
      • findSingleMainClass

        public static String findSingleMainClass(File rootFolder)
                                          throws IOException
        Find a single main class from the given rootFolder.
        Parameters:
        rootFolder - the root folder to search
        Returns:
        the main class or null
        Throws:
        IOException - if the folder cannot be read
      • findSingleMainClass

        public static String findSingleMainClass(File rootFolder,
                                                 String annotationName)
                                          throws IOException
        Find a single main class from the given rootFolder. A main class annotated with an annotation with the given annotationName will be preferred over a main class with no such annotation.
        Parameters:
        rootFolder - the root folder to search
        annotationName - the name of the annotation that may be present on the main class
        Returns:
        the main class or null
        Throws:
        IOException - if the folder cannot be read
      • findMainClass

        public static String findMainClass(JarFile jarFile,
                                           String classesLocation)
                                    throws IOException
        Find the main class in a given jar file.
        Parameters:
        jarFile - the jar file to search
        classesLocation - the location within the jar containing classes
        Returns:
        the main class or null
        Throws:
        IOException - if the jar file cannot be read
      • findSingleMainClass

        public static String findSingleMainClass(JarFile jarFile,
                                                 String classesLocation)
                                          throws IOException
        Find a single main class in a given jar file.
        Parameters:
        jarFile - the jar file to search
        classesLocation - the location within the jar containing classes
        Returns:
        the main class or null
        Throws:
        IOException - if the jar file cannot be read
      • findSingleMainClass

        public static String findSingleMainClass(JarFile jarFile,
                                                 String classesLocation,
                                                 String annotationName)
                                          throws IOException
        Find a single main class in a given jar file. A main class annotated with an annotation with the given annotationName will be preferred over a main class with no such annotation.
        Parameters:
        jarFile - the jar file to search
        classesLocation - the location within the jar containing classes
        annotationName - the name of the annotation that may be present on the main class
        Returns:
        the main class or null
        Throws:
        IOException - if the jar file cannot be read