databene

 
  • Increase font size
  • Default font size
  • Decrease font size

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 requirements to run this Maven plugin:
Maven 2.0.8 or newer
JDK 1.6 or newer

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. It is invoked from the commandline by mvn benerator:generate.

Getting started

First of all, you need a Maven project. If you are about to create a completely new project, you may want to make use of the maven-project-wizard by following these instructions. Otherwise you need to configure the benerator plugin in your project manually. The minimal configuration would be:

<build>
...
<plugins>
<plugin>
<groupId>org.databene</groupId>
<artifactId>maven-benerator-plugin</artifactId>
<version>0.5.8</version>
</plugin>
</plugins>
</build>

This defaults the descriptor path to benerator.xml.

Configuration

You may configure certain aspects of benerator behavior, 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>

This is a complete list of the available options:

  • descriptor: the path to the benerator descriptor file
  • encoding: the file encoding to use as default
  • validate: turn internal (XML an data model) validations off or on
  • dbDriver: the JDBC driver class to use, this setting is provided to benerator as variable dbDriver
  • dbUrl: the JDBC driver class to use, this setting is provided to benerator as variable dbUrl
  • dbSchema: the database schema to use, this setting is provided to benerator as variable dbSchema
  • dbUser: the database user name, this setting is provided to benerator as variable dbUser
  • dbPassword: the database user's passord, this setting is provided to benerator as variable dbPassword
  • scope: the scope of the project dependencies to include in the classpath when running benerator. It can be runtime or test. If left out, it defaults to runtime

 

Extending the classpath


If you need to extend the classpath to libraries different to your project dependencies, you can add them as dependencies to your plugin configuration (this requires Maven 2.0.9 or newer):

    <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 documentation.

For more information, see Maven's "Guide to Configuring Plug-ins"