The most convenient way to use benerator is integrating it into an IDE with maven. Unfortunately, an absolute requirement is that you are familiar with maven - if you are not, create an IDE-based project without Maven support.
Choose or install an IDE
The procedure is described here for Eclipse, but works similarly for other IDEs.
If you do not yet have an IDE installed and would like to use Eclipse, download and install an Eclipse distribution with an XMLÂ editor, e.g. Eclipse IDE for Java Developers from the Eclipse web site.
If your Eclipse installation does not support maven (like the Eclipse IDE for Java), further work is necessary:
Make the IDE support Maven
Install a maven plugin, e.g. m2eclipse.
Here's a step-by-step advisory for Eclipse-newbies:
- Start Eclipse
- Select Help - Software Updates - Find and Install from the main menu
- Choose Search for new features to install and click Next
- Click New Remote Site
- In the Site dialog, set Name to m2eclipse, URL to http://m2eclipse.sonatype.org/update/ and click OK
- Back in the main update dialog, assure that m2eclipse is checked and click Finish
- In the Search Results dialog, choose at least m2eclipse - Maven Integration and click Next
- Choose I accept the terms of the license agreement and click Next
- Click Finish
- Click Install All
- Click Restart
Create a project
You can use a small but powerful wizard for creating a benerator project.
First make sure the necessary JDBC drivers are in the lib directory of the benerator sdistribution, then start the maven-project wizard:
This will open a GUI in which you can enter all project details:
If you do not want to import table (meta) data from an existing database, uncheck the 'Database Project' checkbox.
Otherwise configure your database and click 'Test Connection' to check if they are valid.
These are typical settings for different databases:
|Database||URL ||Driver Class ||Jar |
|DB2 ||Â dbc:db2://host:50000/database||Â com.ibm.db2.jcc.DB2Driver||Â db2jcc.jar|
|Derby ||Â jdbc:derby://host:1527/database||Â org.apache.derby.jdbc.ClientDriver||Â derbyclient.jar|
|Firebird||Â jdbc:firebirdsql:host/3050:database||Â org.firebirdsql.jdbc.FBDriver||Â jaybird-full.jar|
|HSQL||Â jdbc:hsqldb:hsql://host:9001/database||Â org.hsqldb.jdbcDriver||Â hsqldb.jar|
|HSQL (embedded)||Â jdbc:hsqldb:database||Â org.hsqldb.jdbcDriver|
|Jaybird ||Â jdbc:firebirdsql:host/3050:database||Â org.firebirdsql.jdbc.FBDriver||Â jaybird-full.jar|
|MySQL||Â jdbc:mysql://host:3306/database||Â com.mysql.jdbc.Driver||Â mysql-connector-java.jar|
|Oracle||Â jdbc:oracle:thin:@host:1521:XE||Â oracle.jdbc.OracleDriver||Â ojdbc6.jar|
|PostgreSQL||Â jdbc:postgresql://host:5432/database||Â org.postgresql.Driver||Â postgresql-nn.jdbc3.jar|
|Sybase||Â jdbc:jtds:sybase://host:7100/database||Â net.sourceforge.jtds.jdbc.Driver||Â jtds.jar|
For a repeated experiments in a database population project you would generally want to have your database reset completely when starting each data generation. So you should additionally import a SQL file that drops all existing tables and one that recreates them.
Finally click 'Create'.
Benerator will then create a Maven project structure and if you have configured a database, it will connect to the specified database, read the table structures and, if you specified so, read table data and export it to a snapshot file.
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
This is what your project file structure will look like:
The generated pom.xml is the Maven project descriptor which might need modification:
On the one hand it aggregates all supported open source JDBC drivers, the Apache POI library and log4j. You can remove dependencies that you do not need.
On the other hand, some database drivers are not available on the public Maven repository:
- Jaybird (for Firebird DB)
If you need to use one of these you need to manually download and install their Jars in your Maven repository. Possibly they are available at your company's Maven repository, possibly with an unexpected groupId/artifactId.
Â A typical configuration for Oracle would be for example
Â Â Â <groupId>com.oracle</groupId>
Â Â Â <artifactId>ojdbc6</artifactId>
Â Â Â <version>10.2.0.4.0</version>
You can download the Oracle driver from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html and put them into a repository on your own. In a local repository:
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=/path/to/file
or in a remote (e.g. company) repository:
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc6
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=/path/to/file
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â -Durl=[url] -DrepositoryId=[id]
Create IDE configurations for maven goals
- Select Run - Open Run Dialog from the main menu.
- The appearing dialog has a tree at left. Choose Maven Build there and click the New icon.
- In the new right-hand-side panel, replace the name New_configuration with a suitable name, e.g. generate
- Enter clean install benerator:generate in the goal field.
- Click Apply and Close.
You can as well create a snapshot configuration for the goal benerator:dbsnapshot which can be used to create a database dump in DbUnit XML format.
Invoking a Maven goal
Select Run - Open Run Dialog from the main menu. Choose the configuration name defined above, e.g. generate click the Run icon.
Now benerator runs the generated descriptor files.
If you have defined a database project as defined above, benerator connects to your database, deletes the old content, recreates the tables and, if you created a snapshot recreate an identical copy of the original content. Now you are ready to edit the benerator descriptor and try out your generation customizations.
For your convenience the generated descriptor file contains templates for generation configuration of all tables, ordered by dependencies. You can uncomment and modify each attribute you want to generate differently. Originally the count is set to 0 so remember to set it to something higher before you worry;-)