Kohei Nozaki's blog 

Installing Apache Derby to WildFly


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


This post describes how to install Apache Derby 10.11.1.1 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=, \
     --dependencies=javax.api,javax.transaction.api
    
  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, \
     driver-xa-datasource-class-name=org.apache.derby.jdbc.EmbeddedXADataSource)
    
  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
    /system-property=derby.drda.startNetworkServer:add(value=true)
  5. Define a system property to specify the port Derby will be listening
    /system-property=derby.drda.portNumber:add(value="1527")
  6. Define a system property to specify where log file of Derby will be wrote
    /system-property=derby.stream.error.file:add(value="${jboss.server.log.dir}/derby.log")
  7. Define a system property to append derby.log to exist one
    /system-property=derby.infolog.append:add(value="true")
  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 \
     --password=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
    /subsystem=datasources/data-source=DerbyEmbeddedDS:test-connection-in-pool

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.

References



Comments:

Works like a charm. Very helpful step-by-step guide. Maybe one last point: I had to restart Wildfly in order to get a "Success" message in the last step (Test connection).

Thanks a lot for this post.

Posted by Daniel on July 24, 2015 at 07:44 PM JST #


Leave a Comment

HTML Syntax: NOT allowed