Wiki source code of Configure H2

Last modified by Eleni Cojocariu on 2026/11/25 14:43

Show last authors
1 {{warning}}
2 H2 is not one of the [[databases XWiki supports>>dev:Community.SupportStrategy.DatabaseSupportStrategy]] and gets no regular testing. If what you want is an embedded database, [[HSQLDB>>doc:documentation.xs.admin.installation.database.configure-hsqldb.WebHome]] is the supported one.
3 {{/warning}}
4
5 To configure XWiki to use [[H2>>https://h2database.com]], which runs inside the same JVM as XWiki and needs no database server to install or start:
6
7 1. Make sure you have already installed and [[configured a servlet container>>doc:documentation.xs.admin.installation.servlet-container.WebHome]] for XWiki (e.g. [[Tomcat>>doc:documentation.xs.admin.installation.servlet-container.configure-tomcat.WebHome]] or [[Jetty>>doc:documentation.xs.admin.installation.servlet-container.configure-jetty.WebHome]]), with the [[XWiki WAR>>doc:documentation.xs.admin.installation.methods.install-xwiki-war.WebHome]] file extracted/deployed.
8 1. Download H2 from the [[H2 website>>https://www.h2database.com/html/download.html]] or from the [[Maven Central repository>>https://central.sonatype.com/artifact/com.h2database/h2]]. It is a single jar file.
9 1. Copy that jar into the ##WEB-INF/lib## directory of the expanded XWiki WAR. XWiki ships no H2 driver.(((
10 {{code language="none"}}
11 $ cp h2-*.jar /path/to/webapps/xwiki/WEB-INF/lib/
12 {{/code}}
13 )))
14 1. Edit the ##WEB-INF/hibernate.cfg.xml## file, comment out the database block that is currently active and uncomment the H2 one. The shipped connection URL puts the database file in XWiki's [[permanent directory>>doc:documentation.xs.admin.installation.directories.permanent-directory.WebHome]] and needs no editing unless you want it somewhere else.(((
15 {{code language="xml"}}
16 <property name="hibernate.connection.url">jdbc:h2:${environment.permanentDirectory}/database/xwiki</property>
17 <property name="hibernate.connection.username">sa</property>
18 <property name="hibernate.connection.password"></property>
19 <property name="hibernate.connection.driver_class">org.h2.Driver</property>
20 <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
21
22 <property name="hibernate.connection.charSet">UTF-8</property>
23 <property name="hibernate.connection.useUnicode">true</property>
24 <property name="hibernate.connection.characterEncoding">utf8</property>
25
26 <mapping resource="xwiki.hbm.xml"/>
27 <mapping resource="feeds.hbm.xml"/>
28 <mapping resource="instance.hbm.xml"/>
29 <mapping resource="notification-filter-preferences.hbm.xml"/>
30 {{/code}}
31 )))
32 1. Add the mail sender mapping to that list, which the shipped H2 block is missing.(((
33 {{code language="xml"}}
34 <mapping resource="mailsender.hbm.xml"/>
35 {{/code}}
36 )))
37 1. Start or restart the application server. XWiki creates the database and its tables on the first run.
38 1. Verify that the directory in the connection URL now holds the database file.(((
39 {{code language="none"}}
40 $ ls /path/to/permanent/directory/database
41 xwiki.mv.db
42 {{/code}}
43 )))

Get Connected