Running Ibator

Ibator can be run in the following ways:

Each method is described in detail below.

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

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

Running Ibator from the Command Line

Ibator may be run directly from the command line. The JAR manifest includes the name of the default class (org.apache.ibatis.ibator.api.IbatorRunner) or you may specify it yourself. The IbatorRunner 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 Ibator 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: Ibator 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 Ibator. Any id specified in the list must exactly match the value of the id attribute of an <ibatorContext> configuration element. Only ids specified in this list will be active for this run of Ibator. 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 Ibator. 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 Ibator. 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 Ibator XML configuration file to run Ibator from the command line. If the file is named "ibatorConfig.xml", then any of the following command lines will run Ibator:

   java -jar ibator.jar -configfile ibatorConfig.xml
   java -jar ibator.jar -configfile ibatorConfig.xml -overwrite
   java -cp ibator.jar org.apache.ibatis.ibator.api.IbatorRunner -configfile ibatorConfig.xml
   java -cp ibator.jar org.apache.ibatis.ibator.api.IbatorRunner -configfile ibatorConfig.xml -overwrite

Running Ibator from Ant

Ibator 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="ibator"
                classname="org.apache.ibatis.ibator.ant.IbatorAntTask"
                classpath="ibator.jar" />
       <ibator overwrite="true" configfile="ibatorConfig.xml" verbose="false" >
         <propertyset>
           <propertyref name="generated.source.dir"/>
         </propertyset>
       </ibator>
     </target>
   </project>

Ibator 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 Ibator 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: Ibator 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 Ibator. Any id specified in the list must exactly match the value of the id attribute of an <ibatorContext> configuration element. Only ids specified in this list will be active for this run of Ibator. 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 Ibator. 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 Ibator. 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 Ibator will log progress messages to the ant console (if Ant is running in verbose mode). The default is "false".

Notes:

Running Ibator from Java with an XML Configuration File

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

   List<String> warnings = new ArrayList<String>();
   boolean overwrite = true;
   File configFile = new File("ibatorConfig.xml");
   IbatorConfigurationParser cp = new IbatorConfigurationParser(warnings);
   IbatorConfiguration config = cp.parseIbatorConfiguration(configFile);
   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
   Ibator ibator = new Ibator(config, callback, warnings);
   ibator.generate(null);

Notes:

Running Ibator from Java with a Java Based Configuration

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

   List<String> warnings = new ArrayList<String>();
   boolean overwrite = true;
   IbatorConfiguration config = new IbatorConfiguration();

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

   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
   Ibator ibator = new Ibator(config, callback, warnings);
   ibator.generate(null);