Sundararajan's Weblog

  • Java
    November 13, 2006

Learning javac's APIs

Guest Author
There are three APIs of javac:
  • JSR 199 - Java Compiler API. This API can be used to embed java compiler in your program. If you want to see a simple example, you may look at JSR-223 script engine for Java. This code uses JSR 199 to compile Java code from strings and readers into memory byte buffer and load it immediately to execute.
  • JSR 269: Pluggable Annotation Processing API. This API can be used to write your own annotation processors. For a simple example, you may want to look at this file in your JDK 6: $JDK/sample/javac/processing/src/CheckNameProcessor.java. This sample checks naming conventions of the compiled class (such as class name should start with upper case).
  • The Tree API - this API is in "com.sun.source.util" and "com.sun.source.tree" packages. If you want to access abstract syntax trees (read-only) of Java programs, you can use this API [start by casting JavaCompier.getTask() method's return value to JavacTask)

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.