10 Replies Latest reply on Feb 16, 2012 10:30 AM by Ove Ranheim

    H2 module and Web Console

    Ove Ranheim Novice

      Is it possible to import the H2 module (com.h2database.h2) from AS7 into a WAR and map H2 servlet from web.xml? If the h2 driver is added to the deployment it will not be able to connect to the embedded db, as they are running in two different processes.

       

      http://www.h2database.com/html/quickstart.html

       

      If not, is it possible to deploy a JDBC driver and define a datasource as part of the WAR file, using e.g. the jboss-deployment-structure.xml?

       

      Ove

        • 1. Re: H2 module and Web Console
          Will Reichert Newbie

          Yep, I got it working just a second ago and was about to start on a wiki page when I saw your post. The current AS7 build will require a change to the h2 module.xml to successfully load the WebServlet but here are the steps.

           

          1. Modify modules/com/h2database/h2/main/module.xml

          add     <module name="javax.servlet.api"/>

           

          2. Create a war with a METAI-INF/MANIFEST.MF and WEB-INF/web.xml

           

          3. add dependency to META-INF/MANIFEST.MF

          Dependencies: com.h2database.h2

           

          4. add the servlet definition to WEB-INF/web.xml

            <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>

           

          That should allow you to access the h2 console from /{context}/h2/

          If that doesn't work let me know what version of AS7 you are using and what is in your web.xml and MANIFEST

          • 2. Re: H2 module and Web Console
            Ove Ranheim Novice

            Hi Will,

             

            Thanks for your update and investigations. This is at last working out perfectly

             

            Would you be able to submit a patch to AS7 team, and/or  ask them to include the module configuration in AS 7.1. It's a small patch.

             

            The rest is as you say, subject to a Wiki configuration page.

             

            This is great news to me.

             

            Cheers,

            Ove

            • 3. Re: H2 module and Web Console
              Jason Porter Master

              I'd like to see this as part of the Admin Console, not adding the config, but accessing the H2 Web Console

              • 4. Re: H2 module and Web Console
                Jesper Pedersen Master

                -1

                 

                There is a reason it is called "ExampleDS" -- it isn't needed by the server, and should be removed as the first admin task. It is only to make it easier to deploy our sample applications to help people getting started.

                • 5. Re: H2 module and Web Console
                  Ove Ranheim Novice

                  The H2 Console also support other databases, so it is not only bound to H2. Would be possible to provide is an extension to the Admin Console, using a jar with a web-fragmenet in it, which is being picked up by the admin console.

                   

                  It's not necessary to have it part of Admin by default, but a simple option to opt it in would be nice. It's a useful backdoor to data, escpessially on stage deployments.

                   

                  Btw, I updated  AS7-1044 to include the patch instructions from Will.

                  • 6. Re: H2 module and Web Console
                    Will Reichert Newbie

                    Hi Ove, a JIRA was already raised and resolved for adding the module dependency to h2 so that the H2 console can be activated without having to modify the core product.

                     

                    I can certainly understand wanting to have the H2 console as part of the JBoss Management Console when an application uses H2. I myself use H2 to smoke test applications on my local machine and being able to reach the H2 console from the Management console would be convenient but it would break the model I have for the other environments. H2 is the JDBC for my smoke test environent but I use MariaDB and MySQL in other environments and it would be a slippery slope to integrate some database consoles without leaving a way for others. In the end I think the best bet for you and I is to simply activate the H2 Console with the wrapper application and use that to connect to the H2 instance but I am intersted to hear how you are using H2 and where you think it would best fit in the admin console.

                    • 7. Re: H2 module and Web Console
                      Bernd Ruecker Master

                      Hey guys.

                       

                      Deploying the console works perfectly, thanks! Do you know if there is a possibility to access the jboss datasources from the console? Because if you point this on a file it is locked, and so you cannot point the datasource AND the hs console to the same file.  Would be handy for development and demo purposes :-)

                       

                      Thanks & Cheers

                      Bernd

                      • 8. Re: H2 module and Web Console
                        Will Reichert Newbie

                        Hi Bernd,

                         

                        You should be able to point the h2 Console at the same database file as the datasources in Jboss. I am using Jboss 7.1.0.CR1b and am able to connect at the same time. Have you doulbe checked that both are using the same username and password? The only time I recall seeing a message about a locked file is when I entered the wrong password.

                        • 9. Re: H2 module and Web Console
                          Bernd Ruecker Master

                          Right, works! Thanks a lot and sorry...

                          • 10. Re: H2 module and Web Console
                            Ove Ranheim Novice

                            Hi Will,

                             

                            I use the H2 Console through a custom module that is being deployed in dev and stage, but not for production.

                             

                            To connect to MySQL (which I use), I found the Generic JNDI Datasource convenient. In this way do not have any issues with JDBC drivers and dependencies in my app.

                             

                            Thanks for helping out! It works splendidly.