HSQL DB + JBoss + Ant


Do you want to fill/update the contents of the Hypersonic SQL database that is running under JBoss by running an Ant task?
General JBoss info:
In your JBOSS_HOME, you have the server/all, server/default and server/minimal dirs. Usually, one uses the default server set-up configuration, so we are looking at that one.

Recipe for addressing HSQL-DB under JBoss via Ant:

  1. Edit the hsqldb-ds.xml in the server/default/deploy directory.
    Nice feature:
    JBoss automagically detects changes when files are placed/removed/modified in this directory, so once you save your changes, JBoss should automatically incorporate the changes, or start complaining if you did something wrong!

    • Make sure your one and only connection URL entry is as follows:
    • In the </local-tx-datasource> element, make sure that you have an associated
    • Have the following two sections uncommented:
         &lt;mbean code="org.jboss.jdbc.HypersonicDatabase"
           &lt;attribute name="Port"&gt;1701&lt;/attribute&gt;
           &lt;attribute name="Silent"&gt;true&lt;/attribute&gt;
           &lt;attribute name="Database"&gt;fillInYourDB&lt;/attribute&gt;
           &lt;attribute name="Trace"&gt;false&lt;/attribute&gt;
           &lt;attribute name="No_system_exit"&gt;true&lt;/attribute&gt;


         &lt;!-- This mbean can be used when using in process persistent db --&gt;
         &lt;mbean code="org.jboss.jdbc.HypersonicDatabase"
           &lt;attribute name="Database"&gt;fillInYourDB&lt;/attribute&gt;
           &lt;attribute name="InProcessMode"&gt;true&lt;/attribute&gt;
  2. You can now enter an SQL section. We’ll demonstrate a DROP tables one here, since it is the shortest, but once you can drop, you can easily extend to CREATE and INSERT, of course.
    &lt;target name="dropTables"&gt;
      &lt;java classname="org.hsqldb.util.ScriptTool" fork="yes" &gt;
        &lt;arg value="-url"/&gt;
        &lt;arg value="${url}"/&gt;
        &lt;arg value="-database"/&gt;
        &lt;arg value="//localhost:1701"/&gt;
        &lt;arg value="-script"/&gt;
        &lt;arg value="sql/drop.sql"/&gt;
        &lt;classpath refid="hsql.classpath" /&gt;

    The hsql.classpath must have been defined at the top of your build.xml with

     &lt;path id="hsql.classpath"&gt;
        &lt;pathelement location="${jboss.server}/lib/hsqldb.jar"/&gt;

    The SQL script itself is, as you can read, located in the directory sql/drop.sql, relative from the location of build.xml:

    DROP TABLE myTable1;
    DROP TABLE myTable2;
    DROP TABLE myTable3;

    The associated build.properties must at least contain:

  3. Finally, run ant dropTables, and everything should be up and running!

About Author

1 Comment