Class MainClassFinder
- java.lang.Object
- org.springframework.boot.loader.tools.MainClassFinder
public abstract class MainClassFinder extends Object
Finds any class with apublic static main
method by performing a breadth first search.
Constructor Summary
Constructors Constructor Description MainClassFinder()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
findMainClass(File rootFolder)
Find the main class from a given folder.static String
findMainClass(JarFile jarFile, String classesLocation)
Find the main class in a given jar file.static String
findSingleMainClass(File rootFolder)
Find a single main class from the givenrootFolder
.static String
findSingleMainClass(File rootFolder, String annotationName)
Find a single main class from the givenrootFolder
.static String
findSingleMainClass(Collection<File> rootFolders, String annotationName)
Find a single main class from the givenrootFolders
.static String
findSingleMainClass(JarFile jarFile, String classesLocation)
Find a single main class in a given jar file.static String
findSingleMainClass(JarFile jarFile, String classesLocation, String annotationName)
Find a single main class in a given jar file.
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 givenrootFolder
.- 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 givenrootFolder
. A main class annotated with an annotation with the givenannotationName
will be preferred over a main class with no such annotation.- Parameters:
rootFolder
- the root folder to searchannotationName
- 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
findSingleMainClass
public static String findSingleMainClass(Collection<File> rootFolders, String annotationName) throws IOException
Find a single main class from the givenrootFolders
. A main class annotated with an annotation with the givenannotationName
will be preferred over a main class with no such annotation.- Parameters:
rootFolders
- the root folders to searchannotationName
- the name of the annotation that may be present on the main class- Returns:
- the main class or
null
- Throws:
IOException
- if a root folder cannot be read- Since:
- 1.5.5
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 searchclassesLocation
- 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 searchclassesLocation
- 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 givenannotationName
will be preferred over a main class with no such annotation.- Parameters:
jarFile
- the jar file to searchclassesLocation
- the location within the jar containing classesannotationName
- 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