Ibator includes a Maven plugin for integration into a maven build. In keeping with Maven's configuration by convention strategy, including Ibator in a Maven build can be very simple. The minimum configuration is shown below:
<project ...> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.ibatis.ibator</groupId> <artifactId>ibator-maven-plugin</artifactId> <version>1.2.2</version> </plugin> ... </plugins> ... </build> ... </project>
Of course, things are never that easy!
The Ibator Maven plugin includes one goal:
ibator:generate
The goal is not automatically executed by Maven. It can be executed in two ways.
The goal can be executed from the command line with the command:
mvn ibator:generate
You can pass parameters to the goal with standard Maven command line properties. For example:
mvn -Dibator.overwrite=true ibator:generate
This will run Ibator and instruct Ibator to overwrite any existing Java files it may find.
In a continuous build environment, you may want to automatically execute Ibator as a part of a Maven build. This can be accomplished by configuring the goal to execute automatically. An example of this is shown below:
<project ...> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.ibatis.ibator</groupId> <artifactId>ibator-maven-plugin</artifactId> <version>1.2.2</version> <executions> <execution> <id>Generate iBATIS Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> ... </plugins> ... </build> ... </project>
The Ibator plugin is bound to the generate-sources
phase of a
Maven build, so it will execute before the complie step. Also note that
Ibator generates both Java source files and XML resources. The Ibator goal
will bind both generated Java files and XML resources to the build and they
will both be included in any JAR generated by the build.
Any property specified in the POM will be passed into the Ibator configuration file and may be used in the normal way. For example:
<project ...> ... <properties> <dao.target.dir>src/main/java</dao.target.dir> </properties> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.ibatis.ibator</groupId> <artifactId>ibator-maven-plugin</artifactId> <version>1.2.2</version> <executions> <execution> <id>Generate iBATIS Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> ... </plugins> ... </build> ... </project>
In this case, the property may be accessed in the Ibator configuration file with the
syntax ${dao.target.dir}
.
All parameters are optional and have suitable defaults.
Parameter | Expression | Type | Comments |
---|---|---|---|
configurationFile | ${ibator.configurationFile} | java.io.File | The location of the Ibator configuration file.
Default value: ${basedir}/src/main/resources/ibatorConfig.xml |
contexts | ${ibator.contexts} | java.lang.String | 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 parameter is not specified, then all contexts will be active. |
jdbcDriver | ${ibator.jdbcDriver} | java.lang.String | If you specify a sqlScript , then this is the
fully qualified JDBC driver class name to use when connecting to the
database.
|
jdbcPassword | ${ibator.jdbcPassword} | java.lang.String | If you specify a sqlScript , then this is the
password to use when connecting to the database.
|
jdbcURL | ${ibator.jdbcURL} | java.lang.String | If you specify a sqlScript , then this is the
JDBC URL to use when connecting to the database.
|
jdbcUserId | ${ibator.jdbcUserId} | java.lang.String | If you specify a sqlScript , then this is the
JDBC user ID to use when connecting to the database.
|
outputDirectory | ${ibator.outputDirectory} | java.io.File | The directory where files generated by Ibator will be placed.
This directory is used whenever a targetProject in the Ibator
configuration file is set to the special value "MAVEN" (case sensitive).
Default value: ${project.build.directory}/generated-sources/ibator |
overwrite | ${ibator.overwrite} | boolean | If true, then existing Java files will be overwritten if an
existing Java file if found with the same name 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.
Default value: false |
sqlScript | ${ibator.sqlScript} | java.io.File | Location of a SQL script file to run before generating code.
If null, then no script will be run. If not null, then jdbcDriver ,
jdbcURL must be supplied also. In addition,
jdbcUserId |
tableNames | ${ibator.tableNames} | java.lang.String | 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:
|
verbose | ${ibator.verbose} | boolean | If true, then Ibator will write progress messages to the build log. |
The targetProject
attribute of the generator configurations is interpreted
differently when running with Maven. If set to the special value "MAVEN" (case
sensitive), then targetProject
will be set to the plugin's output directory,
and that directory will be created if it doesn't already exist. If not set to "MAVEN", then
targetProject
will be interpreted as normal by Ibator - it must be set
to a directory that already exists.