JDT Core / HowTo: Run the Batch Compiler 
Finding the batch compiler
The batch compiler class is located in the internal classes of the JDT/Core plugin. So it is in the jdtcore.jar file in the directory plugins/org.eclipse.jdt.core. The name of the class is org.eclipse.jdt.internal.compiler.batch.Main
Running the batch compiler
  • Using the main method.
  • Using the main method. The Main class has a main method. This is the classical way to invoke the batch compiler on a command-line.
    • For example on a command-line:

    • java -classpath jdtcore.jar org.eclipse.jdt.internal.compiler.batch.Main -classpath rt.jar A.java
    • For example in a java source:

    • org.eclipse.jdt.internal.compiler.batch.Main.main(new String[] {"-classpath", "rt.jar", "A.java"});
  • Using the static compile(String) method.
  • The compile(String) method is a convenient method to invoke the batch compiler in a java application.
    Instead of:
    • org.eclipse.jdt.internal.compiler.batch.Main.main(new String[] {"-classpath", "rt.jar", "A.java"});
    • you can simply write: org.eclipse.jdt.internal.compiler.batch.Main.compile("-classpath rt.jar A.java");
Which options are available?

With the orange background, these are suggested options.

 
Name Usage
Classpath options
-bootclasspath <dir 1>;<dir 2>;...;<dir P> This is a list of directory or jar files used to bootstrap the class files used by the compiler. By default the libraries of the running VM are used. Entries are separated by the platform path separator.
-cp -classpath <dir 1>;<dir 2>;...;<dir P> This is a list of directory or jar files used to compile the source files. The default value is the value of the property "java.class.path". Entries are separated by the platform path separator.
-d <dir 1>|none This is used to specify in which directory the generated .class files should be dumped. If it is omitted, no package directory structure is created.
If you don't want to generate .class files, use -d none.
-encoding <encoding name> Specify default source encoding format (custom encoding can also be specifed on a per file basis by suffixing each input source file/folder name with [encoding <encoding name>]).
Compliance options
-target 1.1|1.2|1.3|1.4|1.5 This specifies the classfile target setting. The possible value are 1.1 or 1.2, default is 1.2
-1.3 Set compliance level to 1.3. Implicit -source 1.3 -target 1.1.
-1.4 Set compliance level to 1.4 (default). Implicit -source 1.3 -target 1.2.
-1.5 Set compliance level to 1.5. Implicit -source 1.5 -target 1.5.
-source 1.3|1.4|1.5 This is used to enable the assertion support of the compiler. The possible value are: 1.3 or 1.4, default is 1.3 in -1.3 mode and 1.4 in -1.4 mode. In 1.4, assert is treated as a keyword.
Warning options
-warn:
 allDeprecation
|allJavadoc
|assertIdentifier
|charConcat
|conditionAssign
|constructorName
|deprecation
|emptyBlock
|fieldHiding
|finalBound
|finally
|indirectStatic
|intfNonInherited
|javadoc
|localHiding
|maskedCatchBlocks
|nls
|noEffectAssign
|pkgDefaultMethod
|semicolon
|specialParamHiding
|staticReceiver
|syntheticAccess
|tasks(<task1>|...|<taskN>)
|unqualifiedField
|unnecessaryElse
|uselessTypeCheck
|unsafe
|unusedArgument
|unusedImport
|unusedLocal
|unusedPrivate
|unusedThrown
Set warning level.
e.g. -warn:unusedLocals,deprecation

    -warn:    enable exactly the listed warnings
    -warn:+   enable additional warnings
    -warn:-   disable specific warnings
allDeprecation deprecation even inside deprecated code
allJavadoc invalid or missing javadoc
assertIdentifier occurrence of assert used as identifier
charConcat when a char array is used in a string concatenation without being converted explicitely to a string
conditionAssign possible accidental boolean assignment
constructorName method with constructor name
deprecation usage of deprecated type or member outside deprecated code
emptyBlock undocumented empty block
fieldHiding field hiding another variable
finalBound type parameter with final bound
finally finally block not completing normally
intfNonInherited interface non-inherited method compatibility
javadoc invalid javadoc
localHiding local variable hiding another variable
maskedCatchBlocks hidden catch block
nls non-nls string literals (lacking of tags //$NON-NLS-<n>)
noEffectAssign for assignment with no effect
pkgDefaultMethod attempt to override package-default method
semicolon unnecessary semicolon or empty statement
specialParamHiding constructor or setter parameter hiding another field
staticReceiver if a non static receiver is used to get a static field or call a static method
syntheticAccess when performing synthetic access for innerclass
tasks enable support for tasks tags in source code
unqualifiedField unqualified reference to field
unsafe unsafe type operation
unusedArgument unused method argument
unusedImport When enabled, the compiler will issue an error or a warning for unused import reference
unusedLocal unused local variable
unusedPrivate unused private member declaration
unusedThrown unused declared thrown exception
unnecessaryElse unnecessary else clause
uselessTypeCheck unnecessary cast/instanceof operation
-nowarn No warning (equivalent to -warn:none)
-deprecation Equivalent to -warn:deprecation.
Debug options
-g[:none|:lines,vars,source] Set the debug attributes level
-g All debug info (equivalent to -g:lines,vars,source)
-g:none No debug info
-g:[lines,vars,source] Selective debug info
-preserveAllLocals Explicitly request the compiler to preserve all local variables (for debug purpose). If omitted, the compiler will removed unused locals.
Advanced options
@<file> Read command-line arguments from file
-maxProblems <n> Max number of problems per compilation unit (100 by default)
-log <filename> Specify a log file in which all output from the compiler will be dumped. This is really useful if you want to debug the batch compiler or get a file which contains all errors and warnings from a batch build.
-proceedOnError Keep compiling when error, dumping class files with problem methods or problem types. This is recommanded only if you want to be able to run your application even if you have remaining errors.
-verbose Print accessed/processed compilation units in the console or the log file if specified.
-referenceInfo Compute reference info. This is useful only if connected to the builder. The reference infos are useless otherwise.
-progress Show progress (only in -log mode)
-time Display speed information
-noExit Do not call System.exit(n) at end of compilation (n=0 if no error)
-repeat <n> Repeat compilation process <n> times (perf analysis).
-inlineJSR Inline JSR bytecode (implicit if target >= 1.5)
-enableJavadoc Consider references inside javadoc
Helping options
-? -help Display the help message
-v -version Display the build number of the compiler. This is very useful to report a bug.
-showversion Display the build number of the compiler and continue. This is very useful to report a bug.
Examples
d:\temp -classpath rt.jar -time -g -d d:/tmp It compiles all source files in d:\temp and its subfolders. The classpath is simply rt.jar. It generates all debug attributes and all generated .class files are dumped in d:\tmp. The speed of the compiler will be displayed once the batch process is completed.
d:\temp\Test.java -classpath d:\temp;rt.jar -g:none It compiles only Test.java and it will retrieve any dependant files from d:\temp. The classpath is rt.jar and d:\temp, which means that all necessary classes are searched first in d:\temp and then in rt.jar. It generates no debug attributes and all generated .class files are dumped in d:\tmp.