Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start hsqldb server through maven exec plugin failed

Tags:

maven-3

hsqldb

I try to start an hsqldb server for developpement use. I had hsqldb dependency :

<dependency>
   <groupId>org.hsqldb</groupId>
   <artifactId>hsqldb</artifactId>
   <version>2.2.4</version>
</dependency>

I had in build exec-maven-build :

<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/monitoring</argument>
        </arguments>
    </configuration>
</plugin>

And I launch mvn exec:java, server starts and i have this error :

[Server@6e9770a3]: [Thread[org.hsqldb.server.Server.main(),5,org.hsqldb.server.Server]]: Failed to set properties
org.hsqldb.HsqlException: no valid database paths: maformed database enumerator: server.database.0 mem:monitoring

I search through the code, what this error means, and i found in hsqldb code the error on this page => http://hsqldb.svn.sourceforge.net/viewvc/hsqldb/base/tags/2.2.5/src/org/hsqldb/server/Server.java?revision=4369&view=markup

private IntKeyHashMap getDBNameArray() {

    final String  prefix       = ServerProperties.sc_key_dbname + ".";
    final int     prefixLen    = prefix.length();
    IntKeyHashMap idToAliasMap = new IntKeyHashMap();
    Enumeration   en           = serverProperties.propertyNames();

    for (; en.hasMoreElements(); ) {
        String key = (String) en.nextElement();

        if (!key.startsWith(prefix)) {
            continue;
        }

        int dbNumber;

        try {
            dbNumber = Integer.parseInt(key.substring(prefixLen));
        } catch (NumberFormatException e1) {
            **printWithThread("maformed database enumerator: " + key);**

            continue;
        }

        String alias = serverProperties.getProperty(key).toLowerCase();

        if (!aliasSet.add(alias)) {
            printWithThread("duplicate alias: " + alias);
        }

        Object existing = idToAliasMap.put(dbNumber, alias);

        if (existing != null) {
            printWithThread("duplicate database enumerator: " + key);
        }
    }

    return idToAliasMap;
}

So hsqldb use as a key all argument : "no valid database paths: maformed database enumerator: server.database.0 mem:monitoring"

So it looks like a bug, or did I make something wrong ?

OK i found the solution, I changed the way i give arguments to exec maven plugin.

from this :

<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/monitoring</argument>
        </arguments>
    </configuration>
</plugin>

to this :

<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</argument>
            <argument>file:target/monitoring</argument>
        </arguments>
    </configuration>
</plugin>

And it works

like image 555
Antoine Avatar asked Oct 14 '11 12:10

Antoine


2 Answers

I changed the way i pass arguments to exec maven plugin

from this :

<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/monitoring</argument>
        </arguments>
    </configuration>
</plugin>

to this :

<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</argument>
            <argument>file:target/monitoring</argument>
        </arguments>
    </configuration>
</plugin>

And it works

like image 147
Antoine Avatar answered Oct 14 '22 19:10

Antoine


I found out that in case you need to start HSQL in server mode from maven and continue running your integration tests you have to use maven-antrun-plugin and ant Java task as exec-maven-plugin doesn't support forked mode:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <dependencies>
        </dependencies>
        <executions>
          <execution>
            <phase>pre-integration-test</phase>
            <configuration>
              <target>
                <property name="test_classpath" refid="maven.test.classpath" />
                <java classname="org.hsqldb.server.Server"
                  fork="yes" spawn="yes">
                  <arg
                    line="--database.0 mem:test --dbname.0 test" />
                  <classpath>
                    <pathelement path="${test_classpath}" />
                  </classpath>
                </java>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

it assumes your hsqldb dependency is of test scope.

like image 25
user2664404 Avatar answered Oct 14 '22 17:10

user2664404