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.

    Notice that this class loader does not support resoures in the sense of ClassLoader.getResource(String), ClassLoader.getResourceAsStream(String) nd ClassLoader.getResources(String).

    See Also:
    ClassLoaders
    • Field Detail

      • compiledUnitCompilers

        private final java.util.Set<UnitCompiler> compiledUnitCompilers
      • 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,
                                     @Nullable
                                     java.io.File[] sourcePath,
                                     @Nullable
                                     java.lang.String characterEncoding)
        Sets 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
        sourcePath - A collection of directories that are searched for Java source files in the given order
        characterEncoding - The encoding of the Java source files (null for platform default encoding)
      • JavaSourceClassLoader

        public JavaSourceClassLoader​(java.lang.ClassLoader parentClassLoader,
                                     ResourceFinder sourceFinder,
                                     @Nullable
                                     java.lang.String characterEncoding)
        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
        characterEncoding - The encoding of the Java source files (null for platform default encoding)