Lesson 9: Override Model Property Default Values
In several of the previous lessons you have modified property default values governing code generator behavior. The code generator allows you to specify alternate property default values on the command line. This ability is very useful for quick overrides of host-specific paths or directories.
Let's take the JDK model property as an example. The code generator requires access to a JDK during code generation.
You can configure the JDK that you wish to use via the jdk
model property. The JDK property's default value
is ^jdk()
, which is the expression language way of saying: "pick a JDK, any JDK you can find."
What if the expression language cannot locate a JDK on the build host? That's when a command line override comes in very handy.
Step by Step Instructions
- Start the Code Generator GUI
To start the code generator, run
xmog
without the-version
argument. Assuming you are still in the code generator'sbin
directory, simply type:xmog
./xmog
If you run into problems please check out the first lesson.
You should something like this:
The JDK property is initialized to its default value.
- Close the Code Generator
- Restart the Code Generator With a Property Override
Now imagine yourself on a host where the JDK you wish to use is not discoverable by the expression engine or where it picks a JDK that you don't wish to use. Let's start over, but this time specify the JDK default value on the command line. You will have to pick directory names that make sense for your specific host:
xmog "-Djdk=C:\Program Files\Java\jdk1.6.0_28"
./xmog -Djdk=/usr/java/jdk1.6
Note the double quotes to prevent the space in the file name from causing problems. When the GUI comes up, you should see something like this:
Note how the JDK directory is now overridden with the new default value you supplied on the command line. Also note how you do not need to modify the JRE property and other derived properties because their values are calculated from the JDK value.
You can use this technique to override any default value in your model. It is important to understand that only the default property value is overridden. If you set a model property value as part of your model file, that value will always override any default value, be it the original default or an overridden default.
You can also introduce your own custom model properties from the command line and use them in the values of standard model properties. For example, you might introduce a custom property called
libraryDir
and then use it as part of a hard-coded expression for theuserClassPath
property in your model file.
Take-Away Points
- Any model property default value can be overridden from the command line.
- Command line overrides only override a model property's default value.
- If you open a model file that contains a
setmodelproperty()
command for an overridden property, the model file's value "wins", i.e. it overrides the override. - Use command line overrides for host-specific properties like output directories or search paths.