Frames No Frames

Running Abator

Abator can be run in the following ways:

Each method is described in detail below.

Note: there is also an Eclipse plugin for Abator that adds extra function - namely good integration into Eclipse, an Eclipse enabled Ant task, and support for automatic merging of Java files. See the Abator home page for information on installing the Eclipse plugin.

Important: When running outside of an IDE environment like Eclipse, Abator interprets the targetProject and targetPackage attributes in all XML configurations as follows:

Running Abator from the Command Line

Abator may be run directly from the command line. The JAR manifest includes the name of the default class (org.apache.ibatis.abator.api.AbatorRunner) or you may specify it yourself. The AbatorRunner class accepts several arguments as detailed below:

Argument Value
-configfile (required) Specifies the name of the configuration file.
-overwrite (optional) If specified, then existing Java files will be overwritten if an existing Java file if found with the same nae as a generated file. If not specified, and a Java file already exists with the same name as a generated file, then Abator will write the newly generated Java file to the proper directory with a unique name (e.g. MyClass.java.1, MyClass.java.2, etc.). Important: Abator will always merge and overwrite XML files.
-contextids (optional) If specified, then this is a comma delimited list of contexts to use in the current run of Abator. Any id specified in the list must exactly match the value of the id attribute of an <abatorContext> configuration element. Only ids specified in this list will be active for this run of Abator. If this argument is not specified, then all contexts will be active.
-tables (optional) If specified, then this is a comma delimited list of tables to use in the current run of Abator. Any table specified in the list must exactly match the fully qualified table name specified in a <table> configuration element. Only tables specified in this list will be active for this run of Abator. If this argument is not specified, then all tables will be active. Specify table names as:

table
schema.table
catalog..table
etc.

You must create an Abator XML configuration file to run Abator from the command line. If the file is named "abatorConfig.xml", then any of the following command lines will run Abator:

   java -jar abator.jar -configfile abatorConfig.xml
   java -jar abator.jar -configfile abatorConfig.xml -overwrite
   java -cp abator.jar org.apache.ibatis.abator.api.AbatorRunner -configfile abatorConfig.xml
   java -cp abator.jar org.apache.ibatis.abator.api.AbatorRunner -configfile abatorConfig.xml -overwrite

Running Abator from Ant

Abator includes a simple Ant task. The task must be defined in your build.xml file, and the task has three parameters. Here is an example build.xml file:

   <project default="genfiles" basedir=".">
     <property name="generated.source.dir" value="${basedir}" />

     <target name="genfiles" description="Generate the files">
       <taskdef name="abator"
                classname="org.apache.ibatis.abator.ant.AbatorAntTask"
                classpath="abator.jar" />
       <abator overwrite="true" configfile="abatorConfig.xml" verbose="false" >
         <propertyset>
           <propertyref name="generated.source.dir"/>
         </propertyset>
       </abator>
     </target>
   </project>

Abator task attributes are as follows:

Attribute Value
configfile (required) Specifies the name of the configuration file.
overwrite (optional) If "true", "yes", etc., then existing Java files will be overwritten if an existing Java file if found with the same nae as a generated file. If "false", "no", etc., and a Java file already exists with the same name as a generated file, then Abator will write the newly generated Java file to the proper directory with a unique name (e.g. MyClass.java.1, MyClass.java.2, etc.). Important: Abator will always merge and overwrite XML files.
contextids (optional) If specified, then this is a comma delimited list of contexts to use in the current run of Abator. Any id specified in the list must exactly match the value of the id attribute of an <abatorContext> configuration element. Only ids specified in this list will be active for this run of Abator. If this argument is not specified, then all contexts will be active.
tables (optional) If specified, then this is a comma delimited list of tables to use in the current run of Abator. Any table specified in the list must exactly match the fully qualified table name specified in a <table> configuration element. Only tables specified in this list will be active for this run of Abator. If this argument is not specified, then all tables will be active. Specify table names as:

table
schema.table
catalog..table
etc.
verbose (optional) If "true", "yes", etc., then Abator will log progress messages to the ant console. The default is "false".

Notes:

Running Abator from Java with an XML Configuration File

The following code sample shows how to call Abator from Java. It does not show exception handling, but that should be obvious from the compiler errors :)

   List warnings = new ArrayList();  // Abator will add Strings to this list
   boolean overwrite = true;
   File configFile = new File("abatorConfig.xml");
   AbatorConfigurationParser cp = new AbatorConfigurationParser(warnings);
   AbatorConfiguration config = cp.parseAbatorConfiguration(configFile);
   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
   Abator abator = new Abator(config, callback, warnings);
   abator.generate(null);

Notes:

Running Abator from Java with a Java Based Configuration

The following code sample shows how to call Abator from Java only. It does not show exception handling, but that should be obvious from the compiler errors :)

   List warnings = new ArrayList();  // Abator will add Strings to this list
   boolean overwrite = true;
   AbatorConfiguration config = new AbatorConfiguration();

   //   ... fill out the config object as appropriate...

   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
   Abator abator = new Abator(config, callback, warnings);
   abator.generate(null);