Class RuntimeClassScanner1

java.lang.Object
org.daiitech.naftah.utils.reflect.RuntimeClassScanner1

@Deprecated(forRemoval=true) public final class RuntimeClassScanner1 extends Object
Deprecated, for removal: This API element is subject to removal in a future version.
This class is deprecated and marked for removal.
Utility class for scanning runtime classes from the classpath and Java home directories.

This class provides methods to scan class files inside directories and JAR/JMOD archives, and to load them reflectively using different class loaders.

Author:
Chakib Daii
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    The file extension for compiled Java class files.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    Regular expression pattern to match the class file extension .class.
    static final ClassLoader[]
    Deprecated, for removal: This API element is subject to removal in a future version.
    Array of common base package names to be used when scanning classes.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    The Java class path obtained from the system property java.class.path.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    System property key for the Java class path.
    static final Set<String>
    Deprecated, for removal: This API element is subject to removal in a future version.
    A set of class file base names to ignore during scanning.
    static final Set<String>
    Deprecated, for removal: This API element is subject to removal in a future version.
    A set of full class file names to ignore during scanning.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    The file extension for Java archive files (JAR).
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    The Java home directory obtained from the system property java.home.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    System property key for the Java installation directory (JAVA_HOME).
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    The file extension for Java module files (JMOD).
    static final String[]
    Deprecated, for removal: This API element is subject to removal in a future version.
    Array of filesystem paths (directories or archives) used as scan roots.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Deprecated, for removal: This API element is subject to removal in a future version.
    Private constructor to prevent instantiation.
  • Method Summary

    Modifier and Type
    Method
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    Recursively scans for classes inside a directory.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Scans for classes inside a JAR or JMOD file.
    static File
    jarEntryToTempFile(JarFile outerJar, JarEntry innerJarEntry)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Extracts a nested JAR entry from a JAR file and writes it to a temporary file.
    static Class<?>
    loadClass(String className, URLClassLoader classLoader)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Attempts to load a class with the given name using a set of class loaders.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Scans for classes in the default classpath and java home paths.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Scans for classes in the given paths.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CLASS_PATH_PROPERTY

      public static final String CLASS_PATH_PROPERTY
      Deprecated, for removal: This API element is subject to removal in a future version.
      System property key for the Java class path.
      See Also:
    • CLASS_PATH

      public static final String CLASS_PATH
      Deprecated, for removal: This API element is subject to removal in a future version.
      The Java class path obtained from the system property java.class.path. This is a list of paths where classes and resources are searched for.
    • JAVA_HOME_PROPERTY

      public static final String JAVA_HOME_PROPERTY
      Deprecated, for removal: This API element is subject to removal in a future version.
      System property key for the Java installation directory (JAVA_HOME).
      See Also:
    • JAVA_HOME

      public static final String JAVA_HOME
      Deprecated, for removal: This API element is subject to removal in a future version.
      The Java home directory obtained from the system property java.home. Typically points to the directory where the JRE or JDK is installed.
    • PATHS

      public static final String[] PATHS
      Deprecated, for removal: This API element is subject to removal in a future version.
      Array of filesystem paths (directories or archives) used as scan roots. Initialized statically by combining the classpath and Java home paths, filtering out ignored dependencies if available.
    • JAR_EXTENSION

      public static final String JAR_EXTENSION
      Deprecated, for removal: This API element is subject to removal in a future version.
      The file extension for Java archive files (JAR).
      See Also:
    • JMOD_EXTENSION

      public static final String JMOD_EXTENSION
      Deprecated, for removal: This API element is subject to removal in a future version.
      The file extension for Java module files (JMOD).
      See Also:
    • CLASS_EXTENSION

      public static final String CLASS_EXTENSION
      Deprecated, for removal: This API element is subject to removal in a future version.
      The file extension for compiled Java class files.
      See Also:
    • CLASS_EXTENSION_REGEX

      public static final String CLASS_EXTENSION_REGEX
      Deprecated, for removal: This API element is subject to removal in a future version.
      Regular expression pattern to match the class file extension .class. Used to identify class files in file names.
      See Also:
    • IGNORE

      public static final Set<String> IGNORE
      Deprecated, for removal: This API element is subject to removal in a future version.
      A set of class file base names to ignore during scanning. Typically these include special files like module-info and package-info.
    • IGNORE_CLASS

      public static final Set<String> IGNORE_CLASS
      Deprecated, for removal: This API element is subject to removal in a future version.
      A set of full class file names to ignore during scanning. This is the IGNORE set with the .class extension appended.
    • CLASS_LOADERS

      public static final ClassLoader[] CLASS_LOADERS
      Deprecated, for removal: This API element is subject to removal in a future version.
      Array of common base package names to be used when scanning classes. Includes standard Java and popular top-level package prefixes.
  • Constructor Details

    • RuntimeClassScanner1

      private RuntimeClassScanner1()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Private constructor to prevent instantiation. Always throws a NaftahBugError when called.
  • Method Details

    • scanCLasses

      public static Map<String,ScannedClass> scanCLasses()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Scans for classes in the default classpath and java home paths.
      Returns:
      a map of fully qualified class names to their corresponding class loaders (may be null if default)
    • scanCLasses

      public static Map<String,ScannedClass> scanCLasses(String[] paths)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Scans for classes in the given paths.
      Parameters:
      paths - an array of file system paths (directories or JAR files) to scan for classes
      Returns:
      a map of fully qualified class names to their corresponding class loaders (may be null if default)
    • loadClass

      public static Class<?> loadClass(String className, URLClassLoader classLoader)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Attempts to load a class with the given name using a set of class loaders.

      The method tries the predefined class loaders, optionally including the provided URLClassLoader, to load the class without initializing it.

      Parameters:
      className - the fully qualified name of the class to load
      classLoader - an optional URLClassLoader to use for loading the class; may be null
      Returns:
      the Class object if found and loaded successfully; null if the class could not be loaded by any of the class loaders
    • findClassesInDirectory

      public static Map<String,ScannedClass> findClassesInDirectory(File root, File dir)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Recursively scans for classes inside a directory.
      Parameters:
      root - root directory where scanning started
      dir - current directory or file to scan
      Returns:
      a map of fully qualified class names to their corresponding class loaders (null here)
    • findClassesInJar

      public static Map<String,ScannedClass> findClassesInJar(File jarFile)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Scans for classes inside a JAR or JMOD file.
      Parameters:
      jarFile - the JAR or JMOD file to scan
      Returns:
      a map of fully qualified class names to their associated class loaders (null or URLClassLoader for nested jars)
    • jarEntryToTempFile

      public static File jarEntryToTempFile(JarFile outerJar, JarEntry innerJarEntry) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Extracts a nested JAR entry from a JAR file and writes it to a temporary file. The temporary file is deleted on JVM exit.
      Parameters:
      outerJar - the outer JAR file containing the nested JAR entry
      innerJarEntry - the nested JAR entry inside the outer JAR
      Returns:
      a temporary File representing the extracted nested JAR
      Throws:
      IOException - if an I/O error occurs during extraction