From cdd
Jump to: navigation, search

All code generation and parsing is performed by Laja. If you haven't read all the documentation yet, here comes a crash course!

Laja crash course

The project file myproject.laja in the Quick-start guide looks like this:

  srcDir: "{.}/src"

When Laja is installed you can write (from the directory where we have put myproject.laja)

laja myproject


laja myproject.laja

Laja is a template engine that is specialized to produce text files based on templates and data. All files that ends with ".laja" will be handled as templates by Laja and myproject.laja is no exception.

Laja will parse the file myproject.laja and "execute" the macro generateCdd. The macro is included from LAJA_HOME/template/system-imports.laja when Laja is started which has the following import:

#import "{.}/system/cdd/cdd.laja"

...and cdd.laja defines the macro:

#macro generateCdd(parameters)

The macro takes one argument, e.g:

{ srcDir: "{.}/src" }

Curly braces is the Map syntax in Laja. Everything between { and } will be added to an instance of java.util.LinkedHashMap (ordered hash map), so we are actually sending in a map as argument to the macro!

The project file myproject.laja is an ordinary Laja template file. All valid Laja commands can be included, not just the call to generateCdd. We can for example have comments and generate more than one project as in example.laja:

## Generate all examples
#import "{.}/account.laja"
#import "{.}/car.laja"
#import "{.}/computer.laja"
#import "{.}/file.laja"
#import "{.}/person.laja"
#import "{.}/repository.laja"

Project settings

It's time to dig a little deeper into the "project settings" which is represented by the list argument to the macro generateCdd.

Let's say we have the following structure:


...and the content of myproject.laja is:

#set (package = "com/myproject")
  srcDirs: [ "{.}/main/{package}", "{.}/test/{package}" ]

Based on that, let's explain the supported arguments:

Argument Description


Full path to the root of the Java source directory (/projectroot/src/java).


Comma separated list of paths to the root of the Java source directories.


Set to true to show all affected files (default is false), e.g.:

  verbose: true
  srcDir: "{.}/main"

An alternative is to send in the flag "-v", e.g.: laja -v myproject

Strings can contain special elements:

Element Description


Same directory as the current template. If the current template is /projectroot/src/java/myproject.laja then "{.}" will be replaced by "/projectroot/src/java".


Parent directory of the current template. If the current template is /projectroot/src/java/myproject.laja then "{..}" will be replaced by "/projectroot/src".

< Back          Next >