Class JavaSourceClassLoader

  • Direct Known Subclasses:
    CachingJavaSourceClassLoader

    public class JavaSourceClassLoader
    extends AbstractJavaSourceClassLoader
    A ClassLoader that, unlike usual ClassLoaders, does not load byte code, but reads Java™ source code and then scans, parses, compiles and loads it into the virtual machine.

    As with any ClassLoader, it is not possible to "update" classes after they've been loaded. The way to achieve this is to give up on the JavaSourceClassLoader and create a new one.

    • Field Detail

      • precompiledClasses

        private final java.util.Map<java.lang.String,​byte[]> precompiledClasses
        This Map keeps those classes which were already compiled, but not yet defined i.e. which were not yet passed to ClassLoader.defineClass(java.lang.String, byte[], int, int).
      • debugSource

        private boolean debugSource
      • debugLines

        private boolean debugLines
      • debugVars

        private boolean debugVars
    • Constructor Detail

      • JavaSourceClassLoader

        public JavaSourceClassLoader()
      • JavaSourceClassLoader

        public JavaSourceClassLoader​(java.lang.ClassLoader parentClassLoader)
      • JavaSourceClassLoader

        public JavaSourceClassLoader​(java.lang.ClassLoader parentClassLoader,
                                     java.io.File[] optionalSourcePath,
                                     java.lang.String optionalCharacterEncoding)
        Set up a JavaSourceClassLoader that finds Java™ source code in a file that resides in either of the directories specified by the given source path.
        Parameters:
        parentClassLoader - See ClassLoader
        optionalSourcePath - A collection of directories that are searched for Java™ source files in the given order
        optionalCharacterEncoding - The encoding of the Java™ source files (null for platform default encoding)
      • JavaSourceClassLoader

        public JavaSourceClassLoader​(java.lang.ClassLoader parentClassLoader,
                                     ResourceFinder sourceFinder,
                                     java.lang.String optionalCharacterEncoding)
        Constructs a JavaSourceClassLoader that finds Java™ source code through a given ResourceFinder.

        You can specify to include certain debugging information in the generated class files, which is useful if you want to debug through the generated classes (see Scanner(String, Reader)).

        Parameters:
        parentClassLoader - See ClassLoader
        sourceFinder - Used to locate additional source files
        optionalCharacterEncoding - The encoding of the Java™ source files (null for platform default encoding)