Using the Integrated Ant Task

The MyBatis Generator feature includes an integrated Ant task for running MyBatis generator. This Ant task is different from the Ant task included in the basic MyBatis Generator distribution in that it supports Java file merging, and is integrated with the eclipse user interface, logging system, and progress notification system.

It is useful to use the integrated Ant task in the following situations:

Integrated Ant Task Detail

The plug-in declares an Ant task for use within the Eclipse JRE. The task is called "mybatis.generate". Here is an example Ant build file:

<project default="runMyBatisGenerator">
  <target name="runMyBatisGenerator">
    <eclipse.convertPath resourcepath="MBGTest/src/config/generatorConfig.xml"
                         property="thePath"/>
    <mybatis.generate configfile="${thePath}" />
  </target>
</project>

This file uses the Eclipse supplied "eclipse.convertPath" task to calculate the actual path of the configuration file. Then we use the "mybatis.generate" task to run MyBatis Generator. When running this from Eclipse interactively, the Ant launch must be setup to run in the same JRE as the workspace. This setting is a standard configuration setting for running Ant in Eclipse.

The task supports an optional nested <propertyset> element which is the standard Ant property set type. This can be used to pass parameters into a configuration file.

The integrated Ant task supports the following attributes:

Attribute Description
configfile This is the configuration file to use. Use the "eclipse.convertPath" task to convert a workspace path to an absolute path before setting this attribute (as shown above)

This attribute is required.

contextIds If specified, then this is a comma delimited list of contexts to use in the current run of the generator. Any id specified in the list must exactly match the value of the id attribute of a <context> configuration element. Only ids specified in this list will be active for this run. If this attribute is not specified, then all contexts will be active.
fullyQualifiedTableNames If specified, then this is a comma delimited list of tables to use in the current run of the generator. 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. If this attribute is not specified, then all tables will be active. Specify table names as:

table
schema.table
catalog..table
etc.
loggingImplementation If specified, then this selects a specific logging configuration to use during code generation. If you specify a logging implementation, then you must add the implementation to the classpath of the task (or the launch configuration). The supported values are:
  1. SLF4J
  2. COMMONS_LOGGING
  3. LOG4J2
  4. JDK

If you don't specify a value, the task will search for an implementation in the order shown above and use the first one found.