Showing posts with label exec-maven-plugin. Show all posts
Showing posts with label exec-maven-plugin. Show all posts

Thursday, November 8, 2012

Starting/Stopping hsqldb with maven

Starting hsqldb through maven with exec-maven-plugin is straight forward except for the confusion around arguments support.  Here is version with issue:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.2.1</version>
  <executions>
    <execution>
      <goals>
        <goal>java</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <mainClass>org.hsqldb.server.Server</mainClass>
    <arguments>
      <argument>--database.0 file:target/data/tutorial</argument>
    </arguments>
  </configuration>
</plugin>

Issue is with the highlighted line.  The value supplied with argument is passed as a whole single string.  What this means is in your java program argument count would be 1.  To start hsqldb we need to send the key and value for db location as seperate arguments.  We could use either args or nest argument as below:

<configuration>
  <mainClass>org.hsqldb.server.Server</mainClass>
  <args>--database.0 file:target/data/tutorial</args>
</configuration>

<configuration>
  <mainClass>org.hsqldb.server.Server</mainClass>
    <arguments>
      <argument>--database.0</argument>
      <argument>file:target/data/tutorial</argument>
    </arguments>

</configuration>

Now that we started the server, how to stop it?
<configuration>
  <mainClass>org.hsqldb.util.DatabaseManager</mainClass>
  <arguments>
    <argument>-driver</argument>
    <argument>org.hsqldb.jdbcDriver</argument>
    <argument>-url</argument>
    <argument>jdbc:hsqldb:file:test</argument>
    <argument>-user</argument>
    <argument>sa</argument>
  </arguments>
</configuration>

Connect using the UI  manager that comes along hsqldb and execute SHUTDOWN as query.