Article Discussion
The Java Compiler API
Summary: Most developers think of the Java compiler, javac, as an unobtrusive command-line tool to invoke when you want to turn Java source code into class files. The Java Compiler API, JSR 199, released in final form last December, opens up the Java compiler to programmatic interaction as well. Artima spoke with JSR 199 spec lead and Sun engineer Peter von der Ahé about what programmatic compiler access means for developers.
2 posts.
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: April 6, 2007 7:38 PM by Mark
    Posts: 135 / Nickname: fsommers / Registered: January 19, 2002 7:24 AM
    The Java Compiler API
    April 4, 2007 1:00 AM      
    In this interview, Peter von der Ahé explains how the JSR 199 Compiler API opens the Java compiler up to a new class of developer tools that know a lot more about the code being edited. What sorts of features would you like to see in IDEs that can be made possible by the Compiler API?
    • Chris
      Posts: 1 / Nickname: invalidnam / Registered: January 6, 2007 9:16 AM
      Re: The Java Compiler API
      April 5, 2007 6:47 AM      
      I've just started working with the compiler API for an AB5k desklet. It's a lot more than I need, but looking at the API, it's clear that they've anticipated some pretty elaborate uses and provide a significant amount of flexibility for those who are able and willing to take advantage of it. I'm not terribly satisfied with the documentation, though -- creating a compilation task takes an "options" parameter that I have yet to find documentation of.
    • Mark
      Posts: 1 / Nickname: marksw / Registered: April 6, 2007 2:32 PM
      Re: The Java Compiler API
      April 6, 2007 7:38 PM      
      Could this API be used to create a dynamic extension to a running Java application, so that a module receives a block of code and generates a new class, which is then available to the running application? I'm thinking of an eval idea -- the ability to extend dynamically running Java applications. For example, by wrapping the above functionality, you could support something like Ruby's ability to dynamically extend a class -- a module could receive a class file and method code to be added (for example), combine them, and pass them to the API to parse and generate a new class. Then the newly created extended class is available in the same process.