Web Site

org.codehaus.janino
Class Compiler

java.lang.Object
  extended byorg.codehaus.janino.Compiler

public class Compiler
extends Object

A simplified substitute for the javac tool. Usage:

 java org.codehaus.janino.Compiler \
           [ -d destination-dir ] \
           [ -sourcepath dirlist ] \
           [ -classpath dirlist ] \
           [ -extdirs dirlist ] \
           [ -bootclasspath dirlist ] \
           [ -encoding encoding ] \
           [ -verbose ] \
           [ -g:none ] \
           [ -g:{lines,vars,source} ] \
           [ -warn:pattern-list ] \
           source-file ...
 java org.codehaus.janino.Compiler -help
 


Constructor Summary
Compiler(File[] optionalSourcePath, File[] classPath, File[] optionalExtDirs, File[] optionalBootClassPath, File optionalDestinationDirectory, String optionalCharacterEncoding, boolean verbose, DebuggingInformation debuggingInformation, StringPattern[] optionalWarningHandlePatterns, boolean rebuild)
          Initialize a JavaTM compiler with the given parameters.
Compiler(ResourceFinder sourceFinder, IClassLoader iClassLoader, File optionalDestinationDirectory, String optionalCharacterEncoding, boolean verbose, DebuggingInformation debuggingInformation, StringPattern[] optionalWarningHandlePatterns, boolean rebuild)
           
 
Method Summary
 boolean compile(File[] sourceFiles)
          Reads a set of JavaTM compilation units (a.k.a.
static File getClassFile(String className, File sourceFile, File optionalDestinationDirectory)
          Construct the name of a file that could store the byte code of the class with the given name.
static void main(String[] args)
          Command line interface.
 void setStoringClassFiles(boolean storingClassFiles)
          When called with a false argument, then compilation is not terminated, but generated class files are no longer stored in files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Compiler

public Compiler(File[] optionalSourcePath,
                File[] classPath,
                File[] optionalExtDirs,
                File[] optionalBootClassPath,
                File optionalDestinationDirectory,
                String optionalCharacterEncoding,
                boolean verbose,
                DebuggingInformation debuggingInformation,
                StringPattern[] optionalWarningHandlePatterns,
                boolean rebuild)
Initialize a JavaTM compiler with the given parameters.

Classes are searched in the following order:


Compiler

public Compiler(ResourceFinder sourceFinder,
                IClassLoader iClassLoader,
                File optionalDestinationDirectory,
                String optionalCharacterEncoding,
                boolean verbose,
                DebuggingInformation debuggingInformation,
                StringPattern[] optionalWarningHandlePatterns,
                boolean rebuild)
Parameters:
sourceFinder - Finds extra Java compilation units that need to be compiled (a.k.a. "sourcepath")
iClassLoader - loads auxiliary IClasses; e.g. new ClassLoaderIClassLoader(ClassLoader)
optionalDestinationDirectory - where to store the .class files
optionalCharacterEncoding -
verbose -
debuggingInformation - a combination of Java.DEBUGGING_...
optionalWarningHandlePatterns - which warnings to report
rebuild - forces recompilation of all source files, even if up-to-date class files exist
Method Detail

main

public static void main(String[] args)
Command line interface.


setStoringClassFiles

public void setStoringClassFiles(boolean storingClassFiles)
When called with a false argument, then compilation is not terminated, but generated class files are no longer stored in files.


compile

public boolean compile(File[] sourceFiles)
                throws Scanner.ScanException,
                       Parser.ParseException,
                       CompileException,
                       IOException
Reads a set of JavaTM compilation units (a.k.a. "source files") from the file system, compiles them into a set of "class files" and stores these in the file system. Additional source files are parsed and compiled on demand through the "source path" set of directories.

For example, if the source path comprises the directories "A/B" and "../C", then the source file for class "com.acme.Main" is searched in

A/B/com/acme/Main.java
../C/com/acme/Main.java
Notice that it does make a difference whether you pass multiple source files to compile(File[]) or if you invoke compile(File[]) multiply: In the former case, the source files may contain arbitrary references among each other (even circular ones). In the latter case, only the source files on the source path may contain circular references, not the sourceFiles.

Returns:
false if compile errors have occurred
Throws:
Scanner.ScanException
Parser.ParseException
CompileException
IOException

getClassFile

public static File getClassFile(String className,
                                File sourceFile,
                                File optionalDestinationDirectory)
Construct the name of a file that could store the byte code of the class with the given name.

If optionalDestinationDirectory is non-null, the returned path is the optionalDestinationDirectory plus the package of the class (with dots replaced with file separators) plus the class name plus ".class". Example: "destdir/pkg1/pkg2/Outer$Inner.class"

If optionalDestinationDirectory is null, the returned path is the directory of the sourceFile plus the class name plus ".class". Example: "srcdir/Outer$Inner.class"

Parameters:
className - E.g. "pkg1.pkg2.Outer$Inner"
sourceFile - E.g. "srcdir/Outer.java"
optionalDestinationDirectory - E.g. "destdir"

Web Site