Class AbstractJavaSourceClassLoader

java.lang.Object
java.lang.ClassLoader
org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
Direct Known Subclasses:
JavaSourceClassLoader, JavaSourceClassLoader

public abstract class AbstractJavaSourceClassLoader extends ClassLoader
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 AbstractJavaSourceClassLoader and create a new one.

  • Field Details

  • Constructor Details

    • AbstractJavaSourceClassLoader

      public AbstractJavaSourceClassLoader()
    • AbstractJavaSourceClassLoader

      public AbstractJavaSourceClassLoader(ClassLoader parentClassLoader)
  • Method Details

    • getResourceAsStream

      public InputStream getResourceAsStream(String name)
      Overrides:
      getResourceAsStream in class ClassLoader
    • setSourcePath

      public abstract void setSourcePath(File[] sourcePath)
      Parameters:
      sourcePath - The sequence of directories to search for Java source files
    • setSourceFinder

      public abstract void setSourceFinder(ResourceFinder sourceFinder)
      Parameters:
      sourceFinder - Is used when searching for Java source files
    • setSourceFileCharacterEncoding

      public void setSourceFileCharacterEncoding(@Nullable String charsetName)
      Parameters:
      charsetName - if null, use platform default encoding
    • setSourceCharset

      public abstract void setSourceCharset(Charset charset)
      Parameters:
      charset - The character set to using when reading characters from a source file
    • setDebuggingInfo

      public abstract void setDebuggingInfo(boolean lines, boolean vars, boolean source)
      Parameters:
      lines - Whether line number debugging information should be generated
      vars - Whether variables debugging information should be generated
      source - Whether source file debugging information should be generated
    • setProtectionDomainFactory

      public final void setProtectionDomainFactory(@Nullable AbstractJavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory)
      See Also:
    • main

      public static void main(String[] args) throws Exception
      Reads Java source code for a given class name, scan, parse, compile and load it into the virtual machine, and invoke its "main()" method with the given arguments.

      Usage is as follows:

         java AbstractJavaSourceClassLoader [ option ] ... class-name [ argument ] ...
      
         option:
           -sourcepath colon-separated-list-of-source-directories
           -encoding character-encoding
           -g                           Generate all debugging info
           -g:none                      Generate no debugging info
           -g:{source,lines,vars}       Generate only some debugging info
       
      Throws:
      Exception
    • splitPath

      private static File[] splitPath(String string)