Class ClassLoadUtil
java.lang.Object
de.tomatengames.util.ClassLoadUtil
Provides utility methods related to class loading.
Currently focused on methods to load all classes from given jar files.
- Since:
- 1.8
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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".static voidinitializeClass(Class<?> cls) Runs the static initialization of the specified class if it is not already initialized.static ClassLoadReportloadAllClasses(Collection<String> classNames, boolean initialize, ClassLoader classLoader) Loads all classes specified by the given class names using the provided class loader.static ClassLoadReportloadAllClasses(ZipFile jar, boolean initialize, ClassLoader classLoader) Loads all classes from the specified ZIP/JAR file using the provided class loader.
-
Method Details
-
getAllClassNames
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 loadedinitialize- whether the classes should be initialized upon loadingclassLoader- 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 classesinitialize- whether the classes should be initialized upon loadingclassLoader- the class loader to use for loading the classes- Returns:
- a report containing information about successfully loaded and failed classes
-
initializeClass
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 failsReflectionException- if aClassNotFoundExceptionoccurs unexpectedly
-