Class MainClassFinder


  • public abstract class MainClassFinder
    extends java.lang.Object
    Finds any class with a public static main method by performing a breadth first search.
    Author:
    Phillip Webb
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  MainClassFinder.ClassNameCallback<T>
      Callback interface used to receive class names.
    • Constructor Summary

      Constructors 
      Constructor Description
      MainClassFinder()  
    • Method Summary

      Modifier and Type Method Description
      static java.lang.String findMainClass​(java.io.File rootFolder)
      Find the main class from a given folder.
      static java.lang.String findMainClass​(java.util.jar.JarFile jarFile, java.lang.String classesLocation)
      Find the main class in a given jar file.
      static java.lang.String findSingleMainClass​(java.io.File rootFolder)
      Find a single main class from a given folder.
      static java.lang.String findSingleMainClass​(java.util.jar.JarFile jarFile, java.lang.String classesLocation)
      Find a single main class in a given jar file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MainClassFinder

        public MainClassFinder()
    • Method Detail

      • findMainClass

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

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

        public static java.lang.String findMainClass​(java.util.jar.JarFile jarFile,
                                                     java.lang.String classesLocation)
                                              throws java.io.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:
        java.io.IOException - if the jar file cannot be read
      • findSingleMainClass

        public static java.lang.String findSingleMainClass​(java.util.jar.JarFile jarFile,
                                                           java.lang.String classesLocation)
                                                    throws java.io.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:
        java.io.IOException - if the jar file cannot be read