H2 Installation

Last modified by Vincent Massol on 2017/09/06

H2 is a fast, free, in-memory or disk-based java database.

Follow these instructions to use it with XWiki:

  • H2 is a very simple database to configure as you don't need to install nor to start it before being able to use it. It comes as a single JAR file named h2*.jar. You'll need to download this JAR and copy it in your WEB-INF/lib directory.
  • Once this is done, you need to configure XWiki to use H2 and to tell it where the database files will be created. To do this, edit the WEB-INF/hibernate.cfg.xml file where you have expanded the XWiki WAR file and uncommented the H2 part. If you're using an old version of XWiki you won't find a commented out section for H2. In this case, use the following:
    <property name="connection.url">jdbc:h2:${environment.permanentDirectory}/database/xwiki</property>
    <property name="connection.username">sa</property>
    <property name="connection.password"></property>
    <property name="connection.driver_class">org.h2.Driver</property>
    <property name="dialect">org.hibernate.dialect.H2Dialect</property>

Using a JDBC DataSource

<property name="connection.datasource">java:comp/env/jdbc/XWikiDS</property>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>

Using a remote H2 instance

<property name="connection.url">jdbc:h2:tcp://remotehost/xwiki23</property>

On the H2 side, here's one way to have H2 running on a remote machine:

java -cp ./h2-1.2.136.jar org.h2.tools.Server -web -tcp -tcpAllowOthers -baseDir /var/spool/javadb/h2

Thus any database you create will be stored in this location, so with the above example you will have a database called /var/spool/javadb/h2/xwiki23.

Created by Vincent Massol on 2017/09/06
   

Get Connected