Introduction
The benerator plugin enables you to attach benerator to your build cycle or simply use maven and its configuration capabilities for benerator setup and invocation.
System Requirements
The following specifies the minimum requirements to run this Maven plugin:
Maven 2.0
JDK 1.5
Goals Overview
The benerator plugin has three goals:- benerator:createxml: Creates XML files from an XML Schema file, supporting XML Schema annotations for generation setup.
- benerator:dbsnapshot: Creates a database snapshot in DbUnit data file format.
- benerator:generate: Executes benerator using the specified descriptor file. Invoked by mvn benerator:generate.
Getting started
First of all, configure the benerator plugin in your project. The minimal form would be:
<build>
...
<plugins>
<plugin>
<groupId>org.databene</groupId>
<artifactId>maven-benerator-plugin</artifactId>
<version>0.5.4</version>
</plugin>
</plugins>
</build>
This defaults the descriptor path to src/test/benerator/benerator.ben.xml.
Configuration
You may configure certain aspects of benerator behvior, e.g.
<plugin>
<groupId>org.databene</groupId>
<artifactId>maven-benerator-plugin</artifactId>
<version>0.5.4</version>
<configuration>
<descriptor>src/test/benerator/myproject.ben.xml</descriptor>
<encoding>iso-8859-1</encoding>
<dbDriver>oracle.jdbc.driver.OracleDriver</dbDriver>
<dbUrl>jdbc:oracle:thin:@localhost:1521:XE</dbUrl>
<dbSchema>user</dbSchema>
<dbUser>user</dbUser>
<dbPassword>password</dbPassword>
</configuration>
</plugin>
Extending the classpath
In most cases you will need to refer to other libraries, e.g. the database driver or your benerator extensions. As of maven 2.0.9 you can add them as dependencies to your plugin configuration:
<plugin>
<groupId>org.databene</groupId>
<artifactId>maven-benerator-plugin</artifactId>
<version>0.5.4</version>
<configuration>
...
</configuration>
<dependencies>
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</plugin>
Profile-based configuration
In cooperative software development you are supposed to keep your individual configuration private. E.g. you might have individual database configurations on your local development systems. You can then specify them as profile properties in a Maven settings.xml file in your user directory.
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<database.driver>oracle.jdbc.driver.OracleDriver</database.driver>
<database.url>jdbc:oracle:thin:@localhost:1521:XE</database.url>
<database.user>user</database.user>
<database.pwd>user</database.pwd>
</properties>
</profile>
<profiles>
You would then refer them in your POM:
<plugin>
<groupId>org.databene</groupId>
<artifactId>maven-benerator-plugin</artifactId>
<version>0.5.4</version>
<configuration>
<descriptor>src/test/benerator/myproject.ben.xml</descriptor>
<encoding>ISO-8859-1</encoding>
<dbDriver>${database.driver}</dbDriver> <dbUrl>${database.url}</dbUrl> <dbUser>${database.user}</dbUser> <dbPassword>${database.pwd}</dbPassword> <dbSchema>${database.user}</dbSchema></configuration>
</plugin>
Attaching the Mojo to the Build Lifecycle
You can also configure the benerator plugin to attach specific goals to a particular phase of the build lifecycle. Here is an example:
<build>
<plugins>
<plugin>
<groupId>org.databene</groupId>
<artifactId>maven-benerator-plugin</artifactId>
<version>0.5.4</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This causes the benerator goal 'generate' to be executed whenever integration tests are run. For more information on binding a plugin to phases in the lifecycle, please refer to the Build Lifecycle document.





