The JaxMe JavaSource framework

As of Oct 2003, JaxMeJS is discontinued as a standalone project. The further development is happening as a part of the Apache Incubator project. See for details.

This is a framework for generating Java sources. It is based on an abstraction of the Java sources. For instance, there is an object called JavaSource. This object can have embedded instances of JavaMethod or JavaField, it can have inner classes, constructors, and so on. You get the idea. Compared to a basic approach of just using Writer.write(String), the framework has the obvious disadvantage of additional complexity and overhead. However, it also has some advantages:

  1. Your sources become more readable and simpler, for example by automatically importing external classes, if required.
  2. Postprocessing the generated sources is much easier. You get the chance to generate sources in multiple steps, or in a pipeline like this:
    Handle the case
    of a single element
    Handle the case
    of a Collection
  3. Your generator is much more controlled by the compiler and well suited for refactoring. This is best illustrated by looking at the following example:
          JavaMethod jm;
          jm.addLine(MyClass.class, " myInstance = new ", MyClass.class, "();");
    This example assumes the existance of a class "MyClass". The compiler verifies the existance and a refactoring module might, for example, rename this class.
  4. It has a lot of nice shortcuts, for example:
          addLine("int i = Integer.parseInt(s);");
                      JavaSource.getQuoted("Invalid integer argument: "), " + s");

Table of Contents


SourceForge Logo