Usage

The following examples describe the basic usage of the In-Memory Database Maven Plugin.

Basic Configuration

The recommended basic configuration is as follows.

<project>
  ...  
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>com.btmatthews.maven.plugins.inmemdb</groupId>
        <artifactId>inmemdb-maven-plugin</artifactId>
        <version>1.4.3</version>
        <configuration>
          <monitorPort>[port]</monitorPort>
          <monitorKey>[key]</monitorKey>
          <daemon>true|false</daemon>
          <type>hsqldb|derby|h2</type>
          <database>[database name]</database>
          <username>[username]</username>
          <password>[password]</password>
        </configuration>
        <executions>
          <execution>
            <id>start-db</id>
            <goals>
              <goal>run</goal>
            <goals>
            <configuration>
              <sources>
                <source>[filename1]</source>
                <source>[filename2]</source>
                ...
                <source>[filenameN]</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Database types

The following database types are supported:

  • hsqldb - An embedded/in-memory HSQLDB database.
  • derby - An embedded/in-memory Apache Derby database.
  • h2 - An embedded/in-memory H2 database.

File formats

The following file formats are supported:

  • .sql - Contains DDL/DML SQL commands to create the database structure and/or insert test data
  • .csv - A file containing a comma separated value (CSV) data set. The first row of the data set contains the column names and the file name corresponds to the table name.
  • .xml - A file containing a flat DBUnit XML data set.
  • .dbunit.xml - A file containing a DBUnit XML data set.
  • .xls - A Microsoft Excel spread sheet containing one or more work sheets. The name of the work sheet corresponds to the table name and the first row of each work sheet contains the column names.

Example

The following example shows the configuration that could be used to launch in-memory HSQLDB database, create the database schema using a SQL script and populating it from a CSV data set.

<project>
  ...
  <build>
    ...
    <plugins>
      ...
        <groupId>com.btmatthews.maven.plugins.inmemdb</groupId>
        <artifactId>inmemdb-maven-plugin</artifactId>
        <version>1.4.3</version>
        <configuration>
          <monitorPort>11527</monitorPort>
          <monitorKey>inmemdb</monitorKey>
          <type>hsqldb</type>
          <database>.</database>
          <username>sa</username>
          <password></password>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/main/resources/create_database.sql</source>
                <source>src/test/data/test_users.csv</source>
              </sources>
            </configuration>
          </execution>
        </executions>
    </plugins>
  </build>
</project>