title: Why does javac -proc:only option still parse java files when class files already exist?
body: <p>I've got a large java project, and need to perform annotation processing separately to compiling the code.</p>
  
  <p>So I thought about using the<code>-proc</code> option of the <code>javac</code> compiler as follows:</p>
  
  <ol>
  <li><p><code>javac -proc:none ...</code> -- to generate the class files.</p></li>
  <li><p><code>javac -proc:only -processor x.y.z.MyAnnotationProcessor ...</code> -- to examine the class files generated in the previous step and generate code.</p></li>
  </ol>
  
  <p>But it appears that the <code>javac -proc:only</code> option still parses .java files:</p>
  
  <pre><code>$ javac -proc:only -processor x.y.z.MyAnnotationProcessor ... 
  [parsing started RegularFileObject[Foo.java]]
  [parsing completed 14ms]
  [search path for source files: target\classes]
  [search path for class files: ... ]
  ...
  Round 1:
      input files: {Foo}
      annotations: []
      last round: false
  </code></pre>
  
  <p>I would have thought, since a <em>Foo.class</em> file exists in <em>targets/classes</em> and has a timestamp later then the corresponding <em>Foo.java</em> file, that parsing the source file would not be necessary? Is javac really loading the file from disk, parsing it, and constructing an class model in memory, without actually writing the class model to a file? Or does the parsing message relate to the loading of the class file from disk?</p>
  
  <p>The reason this is an issue for me is that I have a source tree with thousands of .java files, and parsing these files twice (once for <code>-proc:none</code> and once for <code>proc:only</code> invocations) takes a long time.</p>
  
  <p>Is there a way of running the annotation processor so that it uses the class files generated from the previous <code>javac -proc:none</code> execution, without (apparently) parsing the same source files again?</p>
  
  <p>Note: I am using JDK 1.7.0_45.</p>
  
  <p><strong>Edit #1</strong></p>
  
  <p>Some more detail:</p>
  
  <p><code>javac -proc:none</code> command and output:</p>
  
  <pre><code>C:\foo&gt; javac -proc:none -verbose src\main\java\x\y\z\*.java
  [parsing started RegularFileObject[src\main\java\x\y\z\Bar.java]]
  [parsing completed 15ms]
  [parsing started RegularFileObject[src\main\java\x\y\z\Baz.java]]
  [parsing completed 0ms]
  [parsing started RegularFileObject[src\main\java\x\y\z\Foo.java]]
  [parsing completed 1ms]
  [search path for source files: .]
  [search path for class files: C:\Program Files\Java\jdk1.7.0_45\jre\lib\resources.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\rt.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\sunrsasign.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\jsse.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\jce.jar,C:\Program    Files\Java\jdk1.7.0_45\jre\lib\charsets.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\jfr.jar,C:\Program Files\Java\jdk1.7.0_45\jre\classes,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\access-bridge-64.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\dnsns.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\jaccess.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\localedata.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunec.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunjce_provider.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunmscapi.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\zipfs.jar,.]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Deprecated.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Retention.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/RetentionPolicy.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Target.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/ElementType.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Annotation.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/AutoCloseable.class)]]
  [wrote RegularFileObject[src\main\java\x\y\z\Bar.class]]
  [checking x.y.z.Baz]
  [wrote RegularFileObject[src\main\java\x\y\z\Baz.class]]
  [checking x.y.z.Foo]
  [wrote RegularFileObject[src\main\java\x\y\z\Foo.class]]
  [total 271ms]
  </code></pre>
  
  <p><code>javac -proc:only</code> command and output:</p>
  
  <pre><code>C:\foo&gt;javac -processorpath processor.jar -proc:only -processor x.y.z.MyAnnotationProcessor -verbose src\main\java\x\y\z\*.java
  [parsing started RegularFileObject[src\main\java\x\y\z\Bar.java]]
  [parsing completed 13ms]
  [parsing started RegularFileObject[src\main\java\x\y\z\Baz.java]]
  [parsing completed 1ms]
  [parsing started RegularFileObject[src\main\java\x\y\z\Foo.java]]
  [parsing completed 1ms]
  [search path for source files: .]
  [search path for class files: C:\Program Files\Java\jdk1.7.0_45\jre\lib\resources.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\rt.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\sunrsasign.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\jsse.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\jce.jar,C:\Program    Files\Java\jdk1.7.0_45\jre\lib\charsets.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\jfr.jar,C:\Program Files\Java\jdk1.7.0_45\jre\classes,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\access-bridge-64.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\dnsns.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\jaccess.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\localedata.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunec.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunjce_provider.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunmscapi.jar,C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\zipfs.jar,.]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Deprecated.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Retention.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/RetentionPolicy.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Target.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/ElementType.class)]]
  [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.7.0_45\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Annotation.class)]]
  Round 1:
      input files: {x.y.z.Bar, x.y.z.Baz, x.y.z.Foo}
      annotations: [java.lang.Deprecated]
      last round: false
  </code></pre>
  
  <p>I also tried adding the <code>-classpath src\main\java\x\y\z</code> and <code>-implicit:none</code> options but java files were still parsed.</p>
  
  <p><strong>Edit #2</strong></p>
  
  <p>Using the <code>-sourcepath src\main\java\</code> and <code>-cp src\main\java\</code> options as suggested:</p>
  
  <pre><code>C:\foo&gt;javac -processorpath processor.jar -proc:only -processor x.y.z.MyAnnotationProcessor -verbose -sourcepath src\main\java -cp src\main\java src\main\java\x\y\z\*.java
  [parsing started RegularFileObject[src\main\java\x\y\z\Bar.java]]
  [parsing completed 14ms]
  [parsing started RegularFileObject[src\main\java\x\y\z\Baz.java]]
  [parsing completed 0ms]
  [parsing started RegularFileObject[src\main\java\x\y\z\Foo.java]]
  [parsing completed 0ms]
  [search path for source files: src\main\java]
  [search path for class files: C:\Program Files\Java\jdk1.7.0_45\jre\lib\resources.jar, ... etc ..., src\main\java ]
  </code></pre>
  
  <p>I had used an incorrect setting for <code>-sourcepath</code> in <strong>Edit #1</strong>, but with the correct <code>-sourcepath</code> as suggested I observe that the source files are still loaded and parsed. </p>
  
  <p>I don't see a way of invoking <code>javac</code> without specifying java source files, so they will always be loaded and parsed. Perhaps the <code>javac -proc:only</code> option may be understood as <em>"java files will be loaded and parsed and annotation processing performed, but the corresponding class files for the parsed java files are not written to disk"</em> ?</p>