Class ClassLoadUtil

java.lang.Object
de.tomatengames.util.ClassLoadUtil

public class ClassLoadUtil extends Object
Provides utility methods related to class loading. Currently focused on methods to load all classes from given jar files.
Since:
1.8
  • Method Details

    • getAllClassNames

      public static Collection<String> getAllClassNames(ZipFile jar)
      Retrieves all fully qualified class names from the specified JAR file by scanning it for entries whose name ends with ".class".
      Parameters:
      jar - the ZIP/JAR file to find classes in
      Returns:
      a collection of fully qualified class names
    • loadAllClasses

      public static ClassLoadReport loadAllClasses(Collection<String> classNames, boolean initialize, ClassLoader classLoader)
      Loads all classes specified by the given class names using the provided class loader.
      Parameters:
      classNames - a collection of fully qualified class names to be loaded
      initialize - whether the classes should be initialized upon loading
      classLoader - the class loader to use for loading the classes
      Returns:
      a report containing information about successfully loaded and failed classes
    • loadAllClasses

      public static ClassLoadReport loadAllClasses(ZipFile jar, boolean initialize, ClassLoader classLoader)
      Loads all classes from the specified ZIP/JAR file using the provided class loader.
      Parameters:
      jar - the ZIP/JAR file containing classes
      initialize - whether the classes should be initialized upon loading
      classLoader - the class loader to use for loading the classes
      Returns:
      a report containing information about successfully loaded and failed classes
    • initializeClass

      public static void initializeClass(Class<?> cls)
      Runs the static initialization of the specified class if it is not already initialized.
      Parameters:
      cls - the class to initialize
      Throws:
      ExceptionInInitializerError - if the initialization fails
      ReflectionException - if a ClassNotFoundException occurs unexpectedly