blob: cb264208af4248e2329b43025cad4d913cb1066d [file]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="STYLESHEET" href="../book.css" charset="ISO-8859-1" type="text/css">
<title>Compiling Java code</title>
<link rel="stylesheet" type="text/css" href="../book.css">
</head>
<body>
<h2> Compiling Java code</h2>
<p> The JDT plug-ins include an incremental and batch Java compiler for building
Java .class files from source code. There is no direct API provided by the
compiler. It is installed as a builder on Java projects. Compilation is triggered
using standard platform build mechanisms.</p>
<p> The platform build mechanism is described in detail in <a href="../../org.eclipse.platform.doc.isv/guide/resAdv_builders.htm" class="XRef">
Incremental project builders</a> .</p>
<h3> Compiling code</h3>
<p> You can programmatically compile the Java source files in a project using
the build API.</p>
<pre><font color="#4444cc">
IProject myProject;
IProgressMonitor myProgressMonitor;
myProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, myProgressMonitor);
</font></pre>
<p>For a Java project, this invokes the Java incremental project builder
(along with any other incremental project builders that have been added
to the project's build spec). The generated .class files are written to
the designated output folder. Additional resource files are also copied to the output folder.&nbsp;</p>
<p>In the case of a full batch build, all the
.class files in the output folder may be 'scrubbed' to ensure that no stale
files are found. This is controlled using a JDT Core Builder Option (<a href="../reference/api/org/eclipse/jdt/core/JavaCore.html#CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER">CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER</a>).&nbsp;
The default for this option is to clean output folders.&nbsp; Unless this option
is reset, you must ensure that you place all .class files for which
you do not have corresponding source files in a separate class file folder
on the classpath instead of the output folder.</p>
<p>The
incremental and batch builders can be configured with other options that
control which resources are copied to the output folder.&nbsp; The following sample shows how to set up a resource filter so that files ending with '.ignore' and folders named 'META-INF',
are not copied to the output folder:</p>
<pre><font color="#4444cc">
Hashtable options = JavaCore.getOptions();
options.put(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, &quot;*.ignore,META-INF/&quot;);
JavaCore.setOptions(options);
</font></pre>
<p> Filenames are filtered out if they match one of the supplied patterns. Entire
folders are filtered out if their name matches one of the supplied folder names
which end in a path separator.</p>
<p> The incremental and batch builders can also be configured to only generate
a single error when the .classpath file has errors. This option is set by
default and eliminates numerous errors.&nbsp; See <a href="jdt_api_options.htm#builder">JDT
Core Builder Options</a> for a complete list of builder-related options and
their defaults. </p>
<p>The compiler can also be configured using <a href="../reference/api/org/eclipse/jdt/core/JavaCore.html"><b>JavaCore</b></a>
options.&nbsp; For example, you can define the severity that should be used for
different kinds of problems that are found during compilation.&nbsp; See <a href="jdt_api_options.htm#compiler">JDT
Core Compiler Options </a>for a complete list of compiler-related options and their defaults. </p>
<p>When programmatically configuring options for the builder or compiler, you
should specify the scope of the option.&nbsp; For example, setting up a
resource filter may apply to a particular project only:</p>
<pre><font color="#4444cc">
Hashtable options = myProject.getOptions(false); // get only the options set up in this project
options.put(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, &quot;*.ignore,META-INF/&quot;);
myProject.setOptions(options);
</font>
</pre>
<h3>Using the batch compiler</h3>
<h4>Finding the batch compiler</h4>
<p>The batch compiler class is located in the JDT Core plug-in.
The name of the class is <i>org.eclipse.jdt.compiler.batch.BatchCompiler</i>.
It is packaged into <code>plugins/org.eclipse.jdt.core_3.4.0.&lt;qualifier&gt;.jar</code>. Since 3.2, it is also available as a separate download.
The name of the file is <code>ecj.jar</code>. Its corresponding source is also available. To get them, go to the <a href="http://download.eclipse.org/eclipse/downloads/">download page</a> and
search for the section <b>JDT Core Batch Compiler</b>. This jar contains the batch compiler and the javac ant adapter.</p>
<p>Since 3.3, this jar also contains the support for jsr199 (Compiler API) and the support for jsr269 (Annotation processing). <b>In order to use the annotations
processing support, a 1.6 VM is required.</b></p>
<p>So it can be used as a standalone application and inside an Ant build outside of Eclipse.</p>
<h4>Running the batch compiler</h4>
<ul>
<li>From the command line.
<p><code><font color="#3366FF">java -jar org.eclipse.jdt.core_3.4.0&lt;qualifier&gt;.jar -classpath rt.jar A.java</font></code></p>
<p>or:</p>
<p><code><font color="#3366FF">java -jar ecj.jar -classpath rt.jar A.java</font></code></p>
</li>
<li>Using the static <code>compile(String commandLine, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress)</code> method of the class BatchCompiler.
<pre><font color="#3366FF">
org.eclipse.jdt.compiler.CompilationProgress progress = null; // instantiate your subclass
org.eclipse.jdt.internal.compiler.batch.BatchCompiler.compile(
"-classpath rt.jar A.java",
new PrintWriter(System.out),
new PrintWriter(System.err),
progress);
</font></pre><p>
You can control how progress is reported, or how the batch compiler is canceled, by subclassing the class <i>org.eclipse.jdt.compiler.CompilationProgress</i>.
</p></li>
</ul>
<h4>Which options are available?</h4>
<p>
The recommended options have an orange background.
</p>
<table BORDER CELLSPACING="2" CELLPADDING="2">
<tr>
<th>Name</th>
<th>Usage</th>
</tr>
<tr>
<th colspan="2">Classpath options</th>
</tr>
<tr>
<td valign=top bgcolor="#FFCCAA" width="250">-bootclasspath &lt;dir&nbsp;1&gt;;&lt;dir&nbsp;2&gt;;...;&lt;dir&nbsp;P&gt;</td>
<td valign=top bgcolor="#FFCCAA">This is a list of directories 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.
<br>Each directory or file can specify access rules for types between '[' and ']'.
<p>If no bootclasspath is specified, the compiler will infer it using the following system properties <code>sun.boot.class.path</code>,
<code>vm.boot.class.path</code> or <code>org.apache.harmony.boot.class.path</code> in this order respectively.</p>
</td>
</tr>
<tr>
<td valign="top" bgcolor="#FFCCAA" width="250">-cp<br>-classpath &lt;dir&nbsp;1&gt;;&lt;dir&nbsp;2&gt;;...;&lt;dir&nbsp;P&gt;</td>
<td valign=top bgcolor="#FFCCAA">This is a list of directories 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.
<br>Each directory or file can specify access rules for types between '[' and ']' (e.g. [-X] to forbid access to type X, [~X] to
discourage access to type X, [+p/X:-p/*] to forbid access to all types in package p but allow access to p/X).
<br>The compiler follows the <code>Class-Path</code> clauses of jar files'
manifests recursively and appends each referenced jar file to the end of the
classpath, provided it is not on the classpath yet.
</td>
</tr>
<tr>
<td valign=top width="250">-extdirs &lt;dir&nbsp;1&gt;;&lt;dir&nbsp;2&gt;;...;&lt;dir&nbsp;P&gt;</td>
<td valign=top>This is a list of directories used to specify the location of extension zip/jar files. Entries are separated by the platform path separator.</td>
</tr>
<tr>
<td valign=top width="250">-endorseddirs &lt;dir&nbsp;1&gt;;&lt;dir&nbsp;2&gt;;...;&lt;dir&nbsp;P&gt;</td>
<td valign=top>This is a list of directories used to specify the location of endorsed zip/jar files. Entries are separated by the platform path separator.</td>
</tr>
<tr>
<td valign=top width="250">-sourcepath &lt;dir&nbsp;1&gt;;&lt;dir&nbsp;2&gt;;...;&lt;dir&nbsp;P&gt;</td>
<td valign=top>This is a list of directories used to specify the source files. Entries are separated by the platform path separator.
<br>Each directory can specify access rules for types between '[' and ']'.</td>
</tr>
<tr>
<td valign=top bgcolor="#FFCCAA" width="250">-d &lt;dir 1&gt;|none</td>
<td bgcolor="#FFCCAA">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.<br>
If you want to generate no .class file at all, use <font color="#3366FF">-d none</font>.</td>
</tr>
<tr>
<td valign=top width="250">-encoding &lt;encoding name&gt;</td>
<td>Specify default source encoding format (custom encoding can also be specified on a per file basis by suffixing each input source file/folder name with <font color="#3366FF">[&lt;encoding name&gt;]</font>,
for example <font color="#3366FF">X.java[utf8]</font>).</td>
</tr>
<tr>
<th colspan="2">Compliance options</th>
</tr>
<tr>
<td valign=top width="250">-target 1.1 to 1.7 or (5, 5.0, etc)</td>
<td>This specifies the .class file target setting.
The possible value are:
<ul>
<li><font color="#3366FF">1.1</font> (major version: 45 minor: 3)</li>
<li><font color="#3366FF">1.2</font> (major version: 46 minor: 0)</li>
<li><font color="#3366FF">1.3</font> (major version: 47 minor: 0)</li>
<li><font color="#3366FF">1.4</font> (major version: 48 minor: 0)</li>
<li><font color="#3366FF">1.5</font>, <font color="#3366FF">5</font> or <font color="#3366FF">5.0</font> (major version: 49 minor: 0)</li>
<li><font color="#3366FF">1.6</font>, <font color="#3366FF">6</font> or <font color="#3366FF">6.0</font> (major version: 50 minor: 0)</li>
<li><font color="#3366FF">1.7</font>, <font color="#3366FF">7</font> or <font color="#3366FF">7.0</font> (major version: 51 minor: 0)</li>
</ul>
Defaults are:
<ul>
<li><font color="#3366FF">1.1</font> in <font color="#3366FF">-1.3</font> mode</li>
<li><font color="#3366FF">1.2</font> in <font color="#3366FF">-1.4</font> mode</li>
<li><font color="#3366FF">1.5</font> in <font color="#3366FF">-1.5</font> mode</li>
<li><font color="#3366FF">1.6</font> in <font color="#3366FF">-1.6</font> mode</li>
<li><font color="#3366FF">1.7</font> in <font color="#3366FF">-1.7</font> mode</li>
</ul>
</td>
</tr>
<tr>
<td valign=top>-1.3</td>
<td>Set compliance level to <font color="#3366FF">1.3</font>. Implicit -source 1.3 -target 1.1.</td>
</tr>
<tr>
<td valign=top>-1.4</td>
<td>Set compliance level to <font color="#3366FF">1.4</font> (default). Implicit -source 1.3 -target 1.2.</td>
</tr>
<tr>
<td valign=top>-1.5</td>
<td>Set compliance level to <font color="#3366FF">1.5</font>. Implicit -source 1.5 -target 1.5.</td>
</tr>
<tr>
<td valign=top>-1.6</td>
<td>Set compliance level to <font color="#3366FF">1.6</font>. Implicit -source 1.6 -target 1.6.</td>
</tr>
<tr>
<td valign=top>-1.7</td>
<td>Set compliance level to <font color="#3366FF">1.7</font>. Implicit -source 1.7 -target 1.7.</td>
</tr>
<tr>
<td valign=top width="250">-source 1.1 to 1.7 or (5, 5.0, etc)</td>
<td>This is used to specify the source level expected by the compiler.<br>
The possible value are:
<ul>
<li><font color="#3366FF">1.3</font></li>
<li><font color="#3366FF">1.4</font></li>
<li><font color="#3366FF">1.5</font>, <font color="#3366FF">5</font> or <font color="#3366FF">5.0</font></li>
<li><font color="#3366FF">1.6</font>, <font color="#3366FF">6</font> or <font color="#3366FF">6.0</font></li>
<li><font color="#3366FF">1.7</font>, <font color="#3366FF">7</font> or <font color="#3366FF">7.0</font></li>
</ul>
Defaults are:
<ul>
<li><font color="#3366FF">1.3</font> in <font color="#3366FF">-1.3</font> mode</li>
<li><font color="#3366FF">1.3</font> in <font color="#3366FF">-1.4</font> mode</li>
<li><font color="#3366FF">1.5</font> in <font color="#3366FF">-1.5</font> mode</li>
<li><font color="#3366FF">1.6</font> in <font color="#3366FF">-1.6</font> mode</li>
<li><font color="#3366FF">1.7</font> in <font color="#3366FF">-1.7</font> mode</li>
</ul>
In <font color="#3366FF">1.4</font>, <font color="#3366FF"><I>assert</I></font> is treated as a keyword. In <font color="#3366FF">1.5</font>
and <font color="#3366FF">1.6</font>, <font color="#3366FF"><I>enum</I></font> and <font color="#3366FF"><i>assert</i></font> are treated as a keywords.</td>
</tr>
<tr>
<th colspan="2">Warning options</th>
</tr>
<tr>
<td valign=top width="250">-warn:<blockquote>allDeprecation<br>allJavadoc<br><font color="#FF0000">assertIdentifier</font><br>boxing<br><font color="#FF0000">charConcat</font><br>conditionAssign<br><font color="#FF0000">constructorName</font>
<br>dep-ann<br><font color="#FF0000">deprecation</font><br><font color="#FF0000">discouraged</font><br>emptyBlock<br>enumSwitch<br>fallthrough<br>fieldHiding<br>finalBound<br><font color="#FF0000">finally</font>
<br><font color="#FF0000">forbidden</font><br>hiding<br>incomplete-switch<br>indirectStatic
<br><font color="#FF0000">intfAnnotation</font><br><font color="#FF0000">intfNonInherited</font><br>javadoc<br>localHiding
<br><font color="#FF0000">maskedCatchBlocks</font><br>nls<br><font color="#FF0000">noEffectAssign</font><br>null<br>nullDereference<br>over-ann<br>paramAssign<br><font color="#FF0000">pkgDefaultMethod</font><br>raw<br>semicolon<br><font color="#FF0000">serial</font><br>
specialParamHiding<br>static-access<br><font color="#FF0000">staticReceiver</font><br>super<br><font color="#FF0000">suppress</font><br>synthetic-access<br>syntheticAccess<br>tasks(&lt;task1&gt;|...|&lt;taskN&gt;)<br>
<font color="#FF0000">typeHiding</font><br><font color="#FF0000">unchecked</font><br>unnecessaryElse<br>unqualified-field-access<br>unqualifiedField<br>unused<br>unusedArgument<br><font color="#FF0000">unusedImport</font><br><font color="#FF0000">unusedLabel</font><br><font color="#FF0000">unusedLocal</font><br><font color="#FF0000">unusedPrivate</font><br>unusedThrown
<br>uselessTypeCheck<br><font color="#FF0000">varargsCast</font><br><font color="#FF0000">warningToken</font>
</blockquote>
</td>
<td valign=top>Set warning level.<br>e.g. <font color="#3366FF">-warn:unusedLocal,deprecation</font><br>
<p>In <font color="#FF0000">red</font> are the default settings.</p>
<pre>
-warn:none disable all warnings
-warn:&lt;warnings separated by ,&gt; enable exactly the listed warnings
-warn:+&lt;warnings separated by ,&gt; enable additional warnings
-warn:-&lt;warnings separated by ,&gt; disable specific warnings
</pre>
<table>
<tr>
<th align=left valign=top>allDeprecation</th>
<td valign=top>deprecation even inside deprecated code</td>
</tr>
<tr>
<th align=left valign=top>allJavadoc</th>
<td valign=top>invalid or missing javadoc</td>
</tr>
<tr>
<th align=left valign=top>assertIdentifier</th>
<td valign=top>occurrence of <i>assert</i> used as identifier</td>
</tr>
<tr>
<th align=left valign=top>boxing</th>
<td valign=top>autoboxing conversion</td>
</tr>
<tr>
<th align=left valign=top>charConcat</th>
<td valign=top>when a char array is used in a string concatenation without being converted explicitly to
a string</td>
</tr>
<tr>
<th align=left valign=top>conditionAssign</th>
<td valign=top>possible accidental boolean assignment</td>
</tr>
<tr>
<th align=left valign=top>constructorName</th>
<td valign=top>method with constructor name</td>
</tr>
<tr>
<th align=left valign=top>dep-ann</th>
<td valign=top>missing @Deprecated annotation</td>
</tr>
<tr>
<th align=left valign=top>deprecation</th>
<td valign=top>usage of deprecated type or member outside deprecated code</td>
</tr>
<tr>
<th align=left valign=top>discouraged</th>
<td valign=top>use of types matching a discouraged access rule</td>
</tr>
<tr>
<th align=left valign=top>emptyBlock</th>
<td valign=top>undocumented empty block</td>
</tr>
<tr>
<th align=left valign=top>enumSwitch,<br>incomplete-switch</th>
<td valign=top>incomplete enum switch</td>
</tr>
<tr>
<th align=left valign=top>fallthrough</th>
<td valign=top>possible fall-through case</td>
</tr>
<tr>
<th align=left valign=top>fieldHiding</th>
<td valign=top>field hiding another variable</td>
</tr>
<tr>
<th align=left valign=top>finalBound</th>
<td valign=top>type parameter with final bound</td>
</tr>
<tr>
<th align=left valign=top>finally</th>
<td valign=top>finally block not completing normally</td>
</tr>
<tr>
<th align=left valign=top>forbidden</th>
<td valign=top>use of types matching a forbidden access rule</td>
</tr>
<tr>
<th align=left valign=top>hiding</th>
<td valign=top>macro for fieldHiding, localHiding, typeHiding and maskedCatchBlock</td>
</tr>
<tr>
<th align=left valign=top>indirectStatic</th>
<td valign=top>indirect reference to static member</td>
</tr>
<tr>
<th align=left valign=top>intfAnnotation</th>
<td valign=top>annotation type used as super interface</td>
</tr>
<tr>
<th align=left valign=top>intfNonInherited</th>
<td valign=top>interface non-inherited method compatibility</td>
</tr>
<tr>
<th align=left valign=top>javadoc</th>
<td valign=top>invalid javadoc</td>
</tr>
<tr>
<th align=left valign=top>localHiding</th>
<td valign=top>local variable hiding another variable</td>
</tr>
<tr>
<th align=left valign=top>maskedCatchBlocks</th>
<td valign=top>hidden catch block</td>
</tr>
<tr>
<th align=left valign=top>nls</th>
<td>non-nls string literals (lacking of tags //$NON-NLS-&lt;n&gt;)</td>
</tr>
<tr>
<th align=left valign=top>noEffectAssign</th>
<td valign=top>assignment with no effect</td>
</tr>
<tr>
<th align=left valign=top>null</th>
<td>potential missing or redundant null check</td>
</tr>
<tr>
<th align=left valign=top>nullDereference</th>
<td>missing null check</td>
</tr>
<tr>
<th align=left valign=top>over-ann</th>
<td>missing @Override annotation</td>
</tr>
<tr>
<th align=left valign=top>paramAssign</th>
<td valign=top>assignment to a parameter</td>
</tr>
<tr>
<th align=left valign=top>pkgDefaultMethod</th>
<td valign=top>attempt to override package-default method</td>
</tr>
<tr>
<th align=left valign=top>raw</th>
<td valign=top>usage a of raw type (instead of a parametrized type)</td>
</tr>
<tr>
<th align=left valign=top>semicolon</th>
<td valign=top>unnecessary semicolon or empty statement</td>
</tr>
<tr>
<th align=left valign=top>serial</th>
<td valign=top>missing serialVersionUID</td>
</tr>
<tr>
<th align=left valign=top>specialParamHiding</th>
<td valign=top>constructor or setter parameter hiding another field</td>
</tr>
<tr>
<th align=left valign=top>static-access</th>
<td valign=top>macro for indirectStatic and staticReceiver</td>
</tr>
<tr>
<th align=left valign=top>staticReceiver</th>
<td valign=top>if a non static receiver is used to get a static field or call a static method</td>
</tr>
<tr>
<th align=left valign=top>super</th>
<td valign=top>overriding a method without making a super invocation</td>
</tr>
<tr>
<th align=left valign=top>suppress</th>
<td valign=top>enable @SuppressWarnings</td>
</tr>
<tr>
<th align=left valign=top>syntheticAccess,<br>synthetic-access</th>
<td valign=top>when performing synthetic access for innerclass</td>
</tr>
<tr>
<th align=left valign=top>tasks</th>
<td valign=top>enable support for tasks tags in source code</td>
</tr>
<tr>
<th align=left valign=top>typeHiding</th>
<td valign=top>type parameter hiding another type</td>
</tr>
<tr>
<th align=left valign=top>unchecked</th>
<td valign=top>unchecked type operation</td>
</tr>
<tr>
<th align=left valign=top>unnecessaryElse</th>
<td valign=top>unnecessary else clause</td>
</tr>
<tr>
<th align=left valign=top>unqualified-field-access,<br>unqualifiedField</th>
<td valign=top>unqualified reference to field</td>
</tr>
<tr>
<th align=left valign=top>unused</th>
<td valign=top>macro for unusedArgument, unusedImport, unusedLabel, unusedLocal, unusedPrivate and unusedThrown</td>
</tr>
<tr>
<th align=left valign=top>unusedArgument</th>
<td valign=top>unused method argument</td>
</tr>
<tr>
<th align=left valign=top>unusedImport</th>
<td valign=top>unused import reference</td>
</tr>
<tr>
<th align=left valign=top>unusedLabel</th>
<td valign=top>unused label</td>
</tr>
<tr>
<th align=left valign=top>unusedLocal</th>
<td valign=top>unused local variable</td>
</tr>
<tr>
<th align=left valign=top>unusedPrivate</th>
<td valign=top>unused private member declaration</td>
</tr>
<tr>
<th align=left valign=top>unusedThrown</th>
<td valign=top>unused declared thrown exception</td>
</tr>
<tr>
<th align=left valign=top>uselessTypeCheck</th>
<td valign=top>unnecessary cast/instanceof operation</td>
</tr>
<tr>
<th align=left valign=top>varargsCast</th>
<td valign=top>varargs argument need explicit cast</td>
</tr>
<tr>
<th align=left valign=top>warningToken</th>
<td valign=top>unhandled warning token in @SuppressWarnings</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign=top>-nowarn</td>
<td>No warning (equivalent to <font color="#3366FF">-warn:none</font>)</td>
</tr>
<tr>
<td valign=top>-deprecation</td>
<td>Equivalent to <font color="#3366FF">-warn:+deprecation</font>.</td>
</tr>
<tr>
<th colspan="2">Debug options</th>
</tr>
<tr>
<td valign=top>-g[:none|:lines,vars,source]
</td>
<td>Set the debug attributes level<br>
<table>
<tr>
<th align=left>-g</th>
<td>All debug info (equivalent to <font color="#3366FF">-g:lines,vars,source</font>)
</td>
</tr>
<tr>
<th align=left>-g:none</th>
<td>No debug info</td>
</tr>
<tr>
<th align=left>-g:[lines,vars,source]</th>
<td>Selective debug info</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign=top>-preserveAllLocals</td>
<td>Explicitly request the compiler to preserve all local variables (for debug purpose). If omitted, the compiler will remove unused locals.</td>
</tr>
<tr>
<th colspan="2">Annotation processing options (require a 1.6 VM or above and are used only if the compliance is 1.6)</th>
</tr>
<tr>
<td>-Akey[=value]</td>
<td valign=top>Annotation processors options that are passed to annotation processors. <code>key</code> is made of identifiers separated by dots</td>
</tr>
<tr>
<td>-proc:[only|none]</td>
<td valign=top>If <code>-proc:only</code> is specified, the annotation processors will run but
no compilation will be performed. If <code>-proc:none</code> is specified, annotation processors
will not be discovered or run; compilation will proceed as if no annotation processors
were found. By default the compiler must search the classpath for annotation
processors, so specifying <code>-proc:none</code> may speed compilation if annotation processing is
not required.</td>
</tr>
<tr>
<td>-processor &lt;class1[,class2,...]&gt;</td>
<td valign=top>Qualified class names of annotation processors to run. If specified, the normal
<a href="http://java.sun.com/javase/6/docs/api/javax/annotation/processing/Processor.html">
processor discovery process</a> will be skipped.</td>
</tr>
<tr>
<td>-processorpath &lt;dir&nbsp;1&gt;;&lt;dir&nbsp;2&gt;;...;&lt;dir&nbsp;P&gt;</td>
<td valign=top>A list of directories or jar files which will be searched for annotation processors.
Entries are separated by the platform path separator. If not specified, the classpath will be searched instead.</td>
</tr>
<tr>
<td>-s &lt;dir&gt;</td>
<td valign=top>The directory where generated source files will be created.</td>
</tr>
<tr>
<td>-XprintProcessorInfo</td>
<td valign=top>Print information about which annotations and which elements a processor is asked to process</td>
</tr>
<tr>
<td>-XprintRounds</td>
<td valign=top>Print information about annotation processing rounds</td>
</tr>
<tr>
<td>-classNames &lt;class1[,class2,...]&gt;</td>
<td valign=top>Qualified names of binary types that need to be processed</td>
</tr>
<tr>
<th colspan="2">Ignored options (for compatibility with javac options)</th>
</tr>
<tr>
<td>-J&lt;option&gt;</td>
<td valign=top>Pass option to the virtual machine</td>
</tr>
<tr>
<td>-X&lt;option&gt;</td>
<td valign=top>Specify non-standard option. -Xemacs is not ignored.</td>
</tr>
<tr>
<td>-X</td>
<td valign=top>Print non-standard options and exit</td>
</tr>
<tr>
<td>-O</td>
<td valign=top>Optimize for execution time</td>
</tr>
<tr>
<th colspan="2">Advanced options</th>
</tr>
<tr>
<td>@&lt;file&gt;</td>
<td valign=top>Read command-line arguments from file</td>
</tr>
<tr>
<td>-maxProblems&nbsp;&lt;n&gt;</td>
<td valign=top>Max number of problems per compilation unit (100 by default)</td>
</tr>
<tr>
<td valign=top>-log &lt;filename&gt;</td>
<td>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. If the extension is <b>.xml</b>, the generated log
will be an xml file.
</td>
</tr>
<tr>
<td valign=top>-Xemacs</td>
<td>Use emacs style to present errors and warnings locations into the console
and regular text logs. XML logs are unaffected by this option. With this option
active, the message:
<br><code><font color="#3366FF">
2. WARNING in /workspace/X.java<br>
(at line 8)...</font></code><br>is presented as:
<br><code><font color="#3366FF">
/workspace/X.java:8: warning: The method...</font></code></td>
</tr>
<tr>
<td valign=top>-proceedOnError</td>
<td>Keep compiling in spite of errors, dumping class files with problem methods or problem types. This is recommended only if you want
to be able to run your application even if you have remaining errors.</td>
</tr>
<tr>
<td valign=top>-verbose</td>
<td>Print accessed/processed compilation units in the console or the log file if specified.</td>
</tr>
<tr>
<td valign=top>-referenceInfo</td>
<td>Compute reference info. This is useful only if connected to the builder. The reference infos are useless otherwise.</td>
</tr>
<tr>
<td valign=top>-progress</td>
<td>Show progress (only in -log mode).</td>
</tr>
<tr>
<td valign=top>-time
</td>
<td>Display speed information.</td>
</tr>
<tr>
<td valign=top>-noExit</td>
<td>Do not call <font color="#3366FF">System.exit(n)</font> at end of compilation (<font color="#3366FF">n=0</font> if no error).</td>
</tr>
<tr>
<td valign=top>-repeat &lt;n&gt;
</td>
<td>Repeat compilation process <font color="#3366FF">&lt;n&gt;</font> times (perf analysis).</td>
</tr>
<tr>
<td valign=top>-inlineJSR</td>
<td>Inline JSR bytecode (implicit if target &gt;= 1.5).</td>
</tr>
<tr>
<td valign=top>-enableJavadoc</td>
<td>Consider references inside javadoc.</td>
</tr>
<tr>
<th colspan="2">Helping options</th>
</tr>
<tr>
<td>-? -help</td>
<td valign=top>Display the help message.</td>
</tr>
<tr>
<td valign=top>-v -version</td>
<td>Display the build number of the compiler. This is very useful to report a bug.</td>
</tr>
<tr>
<td valign=top>-showversion</td>
<td>Display the build number of the compiler and continue. This is very useful to report a bug.</td>
</tr>
</table>
<h4>Examples</h4>
<table>
<tr>
<td valign=top><code><font color="#3366FF">d:\temp -classpath rt.jar -time -g -d d:/tmp</font></code>
</td>
<td valign=top>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.</td>
</tr>
<tr>
<td valign=top><code><font color="#3366FF">d:\temp\Test.java -classpath d:\temp;rt.jar -g:none</font></code>
</td>
<td valign=top>It compiles only Test.java and its dependant files if any, retrieving dependant files from d:\temp. The classpath is d:\temp followed by rt.jar, 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:\temp.</td>
</tr>
</table>
<h3>Using the ant javac adapter</h3>
<p>The Eclipse compiler can be used inside an Ant buildfile using the javac adapter.
In order to use the Eclipse compiler, you simply need to define the <b>build.compiler</b>
property in your buildfile.</p>
<p>In order to get the batch compiler working in an ant buildfile, the ant runtime classpath needs to contain the
Eclipse batch compiler. When you run your ant buildfile:</p>
<ol>
<li>outside of Eclipse: the easiest way to set up the ant runtime classpath is to add the <code>ecj.jar</code> file using the <code>-lib</code>
argument or dumping it inside the <code>ANT_HOME</code> location.</li>
<li>inside Eclipse using the same JRE than Eclipse: the Eclipse batch compiler is implicitely added to the ant runtime
classpath.</li>
<li>inside Eclipse using the different JRE: the Eclipse batch compiler must be explicitely added to the ant runtime classpath.
This can be done using the <code>ecj.jar</code> file or using the org.eclipse.jdt.core jar file and the <code>jdtCompilerAdapter.jar</code> file located inside the
org.eclipse.jdt.core jar file (this jar file needs to be extracted first).</li>
</ol>
<p>Here is a small example:</p>
<pre><font color="#4444cc">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project name=&quot;compile&quot; default=&quot;main&quot; basedir=&quot;../.&quot;&gt;
<b>&lt;property name=&quot;build.compiler&quot; value=&quot;org.eclipse.jdt.core.JDTCompilerAdapter&quot;/&gt;</b>
&lt;property name=&quot;root&quot; value=&quot;${basedir}/src&quot;/&gt;
&lt;property name=&quot;destdir&quot; value=&quot;d:/temp/bin&quot; /&gt;
&lt;target name=&quot;main&quot;&gt;
&lt;javac srcdir=&quot;${root}&quot; destdir=&quot;${destdir}&quot; debug=&quot;on&quot; nowarn=&quot;on&quot; extdirs=&quot;d:/extdirs&quot; source=&quot;1.4&quot;&gt;
&lt;classpath&gt;
&lt;pathelement location=&quot;${basedir}/../org.eclipse.jdt.core/bin&quot;/&gt;
&lt;/classpath&gt;
&lt;/javac&gt;
&lt;/target&gt;
&lt;/project&gt;
</font>
</pre><p>The syntax used for the javac Ant task can be found in the <a href="http://ant.apache.org/manual/CoreTasks/javac.html">
Ant javac task documentation</a>. The current adapter supports the Javac Ant task 1.4.1 up to 1.6.5 versions.</p>
<p>If you are using a version above 1.5.0, you can use the nested compiler argument element to specify compiler
specific options.
</p>
<pre><font color="#4444cc">
...
&lt;javac srcdir=&quot;${root}&quot; destdir=&quot;${destdir}&quot; debug=&quot;on&quot; nowarn=&quot;on&quot; extdirs=&quot;d:/extdirs&quot; source=&quot;1.4&quot;&gt;
&lt;classpath&gt;
&lt;pathelement location=&quot;${basedir}/../org.eclipse.jdt.core/bin&quot;/&gt;
&lt;/classpath&gt;
&lt;compilerarg compiler=&quot;org.eclipse.jdt.core.JDTCompilerAdapter&quot; line=&quot;-1.5 -warn:+boxing&quot;/&gt;
&lt;/javac&gt;
...
</font>
</pre><p>To prevent from getting compiler dependant buildfiles, we advise you to use the compiler argument set to <code>org.eclipse.jdt.core.JDTCompilerAdapter</code>.
If this is not set, the buildfile can only be used with the Eclipse compiler. If set, the nested compiler argument is ignored if the name is different from the
compiler name specified by the <code>build.compiler</code> property.</p>
<h3> Problem determination</h3>
<p> JDT Core defines a specialized marker (marker type "<b>org.eclipse.jdt.core.problem</b>
") to denote compilation problems. To programmatically discover problems
detected by the compiler, the standard platform marker protocol should be
used. See <a href="../../org.eclipse.platform.doc.isv/guide/resAdv_markers.htm" class="XRef">
Resource Markers</a>
for an overview of using markers.</p>
<p> The following snippet finds all Java problem markers in a compilation
unit.</p>
<pre><font color="#4444cc">
public IMarker[] findJavaProblemMarkers(ICompilationUnit cu)
throws CoreException {
IResource javaSourceFile = cu.getUnderlyingResource();
IMarker[] markers =
javaSourceFile.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER,
true, IResource.DEPTH_INFINITE);
}
</font>
</pre><p> Java problem markers are maintained by the Java project builder and are
removed automatically as problems are resolved and the Java source is recompiled.</p>
<p>The problem id value is set to one of the constants defined in <b><a href="../reference/api/org/eclipse/jdt/core/compiler/IProblem.html">
IProblem</a>
</b>. The problem's id is reliable, but the message is localized and therefore
can be changed according to the default locale. The constants defined in <b><a href="../reference/api/org/eclipse/jdt/core/compiler/IProblem.html">
IProblem</a>
</b> are self-descriptive. </p>
<p>An implementation of <b><a href="../reference/api/org/eclipse/jdt/core/IProblemRequestor.html">
IProblemRequestor</a>
</b> should be defined to collect the problems discovered during a Java operation.
Working copies can be reconciled with problem detection if a <b><a href="../reference/api/org/eclipse/jdt/core/IProblemRequestor.html">
IProblemRequestor</a>
</b> has been supplied for the working copy creation. To achieve this, you
can use the <b><a href="../reference/api/org/eclipse/jdt/core/ICompilationUnit.html#reconcile(int, boolean, org.eclipse.jdt.core.WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)">
reconcile</a></b> method. Here is an example:</p>
<pre><font color="#4444cc">
ICompilationUnit unit = ..; // get some compilation unit
// create requestor for accumulating discovered problems
IProblemRequestor problemRequestor = new IProblemRequestor() {
public void acceptProblem(IProblem problem) {
System.out.println(problem.getID() + &quot;: &quot; + problem.getMessage());
}
public void beginReporting() {}
public void endReporting() {}
public boolean isActive() { return true; } // will detect problems if active
};
// use working copy to hold source with error
ICompilationUnit workingCopy = unit.getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
((IOpenable)workingCopy).getBuffer().setContents(&quot;public class X extends Zork {}&quot;);
// trigger reconciliation
workingCopy.reconcile(NO_AST, true, null, null);
</font></pre>
<p>You can add an action on the reported problems in the acceptProblem(IProblem)
method. In this example, the reported problem will be that <b>Zork cannot
be resolved or is not a valid superclass</b> and its id is <b>IProblem.SuperclassNotFound</b>.
</p>
<h3>Excluding warnings using <code>SuppressWarnings</code></h3>
<p>Java 5.0 offers the option to the user to disable compilation warnings relative to a subset of a compilation unit using
the annotation <code>java.lang.SuppressWarning</code>.</p>
<pre>
@SuppressWarning("unused") public void foo() {
String s;
}
</pre>
<p>Without the annotation, the compiler would complain that the local variable <code>s</code> is never used.
With the annotation, the compiler silently ignores this warning locally to the <code>foo</code> method. This enables to
keep the warnings in other locations of the same compilation unit or the same project.</p>
<p>The list of tokens that can be used inside an <code>SuppressWarning</code> annotation is:</p>
<!-- cross-checked with the code for 3.2 RC4 by maxime 20060517 -->
<ul>
<li><font color="green">all</font> to suppress all warnings</li>
<li><font color="green">boxing</font> to suppress warnings relative to boxing/unboxing operations</li>
<li><font color="green">cast</font> to suppress warnings relative to cast operations</li>
<li><font color="green">dep-ann</font> to suppress warnings relative to deprecated annotation</li>
<li><font color="green">deprecation</font> to suppress warnings relative to deprecation</li>
<li><font color="green">fallthrough</font> to suppress warnings relative to missing breaks in switch statements</li>
<li><font color="green">finally</font> to suppress warnings relative to finally block that don't return</li>
<li><font color="green">hiding</font> to suppress warnings relative to locals that hide variable</li>
<li><font color="green">incomplete-switch</font> to suppress warnings relative to missing entries in a switch statement (enum case)</li>
<li><font color="green">nls</font> to suppress warnings relative to non-nls string literals</li>
<li><font color="green">null</font> to suppress warnings relative to null analysis</li>
<li><font color="green">restriction</font> to suppress warnings relative to usage of discouraged or forbidden references</li>
<li><font color="green">serial</font> to suppress warnings relative to missing serialVersionUID field for a serializable class</li>
<li><font color="green">static-access</font> to suppress warnings relative to incorrect static access</li>
<li><font color="green">synthetic-access</font> to suppress warnings relative to unoptimized access from inner classes</li>
<li><font color="green">unchecked</font> to suppress warnings relative to unchecked operations</li>
<li><font color="green">unqualified-field-access</font> to suppress warnings relative to field access unqualified</li>
<li><font color="green">unused</font> to suppress warnings relative to unused code</li>
</ul>
</body>
</html>