databene

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

My first IDE-based benerator project

Benerator can be easily called from an IDE. This has the advantage of having a convenient way to launch Benerator (as Java application) and use an integrated debugger for spotting problems. The source code of all benerator libraries is available in the respective directories on the public maven repository:

The following steps are described for Eclipse but can be applied for other IDEs in a very similar fashion:

Create a Java Project

In the Eclipse main menu, choose File - New - Java - Java Project:

 

 

Click 'Next.'

Enter a project name, e.g. 'helloworld' and make sure that a JDK or JRE 1.6 is selected:

 

 

Click 'Next'

Choose the Libraries panel, click 'Add External JARs' and select all libraries from the benerator installation's lib directory.Select 'Add Class Folder' and choose the project's root directory (this is necessary for finding the log4j configuration file).

 

 

Click 'Finish'

 

Create a Benerator descriptor file

Create a file benerator.xml in the project's root directory. Copy & paste the following text into the file:


<?xml version="1.0" encoding="iso-8859-1"?>
<setup
    xmlns="http://databene.org/benerator/0.7.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://databene.org/benerator/0.7.0 http://databene.org/benerator-0.7.0.xsd">
    
    <import defaults="true"/>

    <comment>Greeting the planet...</comment>
    <generate name="greeting" count="10" consumer="ConsoleExporter">
        <attribute name="salutation" values="Hello,Howdy,Hi"/>
        <attribute name="name" values="World,Earth,Planet" />
    </generate>

</setup>

 

Create a log4j configuration file

Create a file log4j.xml in the project's root folder and paste in the following content:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
      <param name="Target" value="System.out"/>
      <param name="Threshold" value="debug"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p (%t) [%c{1}] %m%n"/>
      </layout>
   </appender>
    <category name="org.apache">
       <priority value="warn"/>
    </category>
    <category name="org.databene">
       <priority value="info"/>
    </category>
    <root>
        <priority value="info"/>
        <appender-ref ref="CONSOLE"/>
    </root>
</log4j:configuration>

 

 

Create a Launch Configuration

In the main menu, select Run - Run Configurations.

In the left part of the dialog, select 'Java Application', click the 'New launch confguration' button from the top-left toolbar.

Enter an appropriate configuration name, e.g. 'helloworld generation'.

Choose 'org.databene.benerator.main.Benerator' as main clas:

 

 

Click 'Apply' and 'Run'

Now a Run Configuration is created and benerator executes on the descriptor file to generate Hello word greeting objects like these:

greeting[salutation=Howdy, name=World]
greeting[salutation=Hello, name=Earth]
greeting[salutation=Hello, name=Earth]
greeting[salutation=Hello, name=Earth]
greeting[salutation=Hello, name=Planet]
greeting[salutation=Hi, name=World]
greeting[salutation=Hi, name=Planet]
greeting[salutation=Hello, name=Earth]
greeting[salutation=Hello, name=World]
greeting[salutation=Hi, name=Planet]

 

Run Benerator again

The created launch configuration now is conveniently available by the 'Run' button's drop down list: