Version 2

    The H2 database is build into JBoss AS7 as an example datasource and is an excellent option for quickly building functional applications. H2 offers a fully functional admin console that is not accessible under the default configuration in AS up to 7.1.0.b1. The following instructions will allow you to use the console to setup and administer H2 Databases.

     

     

    Add the the javax.servlet.api module dependency to h2 by editing ./modules/com/h2database/h2/main/module.xml. The file should now look like the following example:

    <module xmlns="urn:jboss:module:1.1" name="com.h2database.h2">
      <resources>
        <resource-root path="h2-1.3.161.jar"/>
            <!-- Insert resources here -->
      </resources>
      <dependencies>
        <module name="javax.api"/>
        <module name="javax.servlet.api"/>
        <module name="javax.transaction.api"/>
      </dependencies>
    </module>
    

     

    Next we need to create a web application wich will act as a wrapper for the H2 Console servlet. I called mine h2Wrapper (because I'm lazy) and it only contains a web.xml and MANIFEST.MF

    h2Wrapper
      ./WebContent
        ./META-INF
           MANIFEST.MF
        ./WEB-INF
           web.xml  
    

     

    The MANIFEST.MF file needs to list the module dependency on h2 to work with the new classloader style in AS7. My MANIFEST.MF is below:

    Manifest-Version: 1.0
    Class-Path: 
    Dependencies: com.h2database.h2
    

     

    Next I just copied the servlet definition from the h2database web site (http://www.h2database.com/html/tutorial.html#using_jooq). My web.xml is below

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
      <display-name>h2Wrapper</display-name>
      <servlet>
        <servlet-name>H2Console</servlet-name>
        <servlet-class>org.h2.server.web.WebServlet</servlet-class>
        <init-param>
          <param-name>webAllowOthers</param-name>
          <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>H2Console</servlet-name>
        <url-pattern>/h2/*</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    

     

    At this point I'm able to load the H2 console from /h2Wrapper/h2/

     

    Hope this helps you more quickly test and deploy applications using the integrated H2 database.