Kohei Nozaki's blog 

Entries tagged [derby]

Installing Apache Derby to WildFly

Posted on Saturday Jan 10, 2015 at 02:29PM in Technology

This post describes how to install Apache Derby as Embedded Server to WildFly 8.2.0.Final. following instructions are intended to use with jboss-cli.

  1. Install jars of Derby as a module into WildFly (assume jar files are located in /tmp)
    module add \
     --name=org.apache.derby \
     --resources=/tmp/derby.jar,/tmp/derbynet.jar,/tmp/derbytools.jar \
     --resource-delimiter=, \
  2. Register JDBC Driver named "derby-embedded"
    /subsystem=datasources/jdbc-driver=derby-embedded:add(driver-name=derby-embedded, \
     driver-module-name=org.apache.derby, \
     driver-class-name=org.apache.derby.jdbc.EmbeddedDriver, \
     driver-datasource-class-name=org.apache.derby.jdbc.EmbeddedDataSource, \
  3. Deploy a MBean which executes the shutdown procedure of Derby
    git clone https://github.com/lbtc-xxx/derby-shutdown-service
    cd derby-shutdown-service; mvn clean package
    cp target/derby-shutdown-service.jar $WILDFLY_HOME/standalone/deployments
  4. Define a system property which triggers Derby to listen a port
  5. Define a system property to specify the port Derby will be listening
  6. Define a system property to specify where log file of Derby will be wrote
  7. Define a system property to append derby.log to exist one
  8. (For Hibernate user) Add following dependency to modules/system/layers/base/org/hibernate/main/module.xml
    <module name="org.apache.derby"/>
    This prevents following warning:
    WARN  [org.hibernate.dialect.DerbyDialect] (ServerService Thread Pool -- 72) HHH000328: Unable to load/access derby driver class sysinfo to check versions : org.apache.derby.tools.sysinfo from [Module "org.hibernate:main" from local module loader @11028347 (finder: local module finder @14899482 (roots: /Users/kyle/servers/wildfly-8.2.0.Final/modules,/Users/kyle/servers/wildfly-8.2.0.Final/modules/system/layers/base))]
  9. Define a DataSource
  10. For Regular DataSource:

    data-source add \
     --name=DerbyEmbeddedDS \
     --driver-name=derby-embedded \
     --connection-url=jdbc:derby:${jboss.server.base.dir}/derbydata;create=true \
     --jndi-name=java:jboss/jdbc/DerbyEmbeddedDS \
     --user-name=app \

    For XA DataSource:

    xa-data-source add \
     --name=DerbyEmbeddedXADS \
     --driver-name=derby-embedded \
     --jndi-name=java:jboss/jdbc/DerbyEmbeddedXADS \
     --user-name=app \
     --password=app \
     --same-rm-override=false \
     --xa-datasource-properties={ \
      "DatabaseName" => "${jboss.server.base.dir}/derbyxadata", \
      "CreateDatabase" => "create"}

  11. Test connection

Also you need to ensure that shutdown script such as /etc/init.d/wildfly to not execute forcing termination (kill -9) unexpectedly. it will be triggered by exceed timeout of 30 seconds as default and it may bring database corruption in case that executing force shutdown during shutdown process of Derby. I think that longer timeout would be considerable for poor environment.