Wiki source code of Configure H2
Last modified by superadmin on 2026/11/25 21:31
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 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.install-relational-database.configure-hsqldb.WebHome]] is the supported one. | ||
| 3 | {{/warning}} | ||
| 4 | |||
| 5 | 1. Make sure you have already installed and [[configured a servlet container>>doc:documentation.xs.admin.installation.deploy-servlet-container.WebHome]] for XWiki (e.g. [[Tomcat>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-tomcat.WebHome]] or [[Jetty>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-jetty.WebHome]]), with the [[XWiki WAR>>doc:documentation.xs.admin.installation.methods.install-xwiki-war.WebHome]] file extracted/deployed. | ||
| 6 | 1. Download [[H2>>https://h2database.com]] 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. | ||
| 7 | 1. Copy that jar into the ##WEB-INF/lib## directory of the expanded XWiki WAR. XWiki ships no H2 driver.((( | ||
| 8 | {{code language="none"}} | ||
| 9 | $ cp h2-*.jar /path/to/webapps/xwiki/WEB-INF/lib/ | ||
| 10 | {{/code}} | ||
| 11 | ))) | ||
| 12 | 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.((( | ||
| 13 | {{code language="xml"}} | ||
| 14 | <property name="hibernate.connection.url">jdbc:h2:${environment.permanentDirectory}/database/xwiki</property> | ||
| 15 | <property name="hibernate.connection.username">sa</property> | ||
| 16 | <property name="hibernate.connection.password"></property> | ||
| 17 | <property name="hibernate.connection.driver_class">org.h2.Driver</property> | ||
| 18 | <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property> | ||
| 19 | |||
| 20 | <property name="hibernate.connection.charSet">UTF-8</property> | ||
| 21 | <property name="hibernate.connection.useUnicode">true</property> | ||
| 22 | <property name="hibernate.connection.characterEncoding">utf8</property> | ||
| 23 | |||
| 24 | <mapping resource="xwiki.hbm.xml"/> | ||
| 25 | <mapping resource="feeds.hbm.xml"/> | ||
| 26 | <mapping resource="instance.hbm.xml"/> | ||
| 27 | <mapping resource="notification-filter-preferences.hbm.xml"/> | ||
| 28 | {{/code}} | ||
| 29 | ))) | ||
| 30 | 1. Add the mail sender mapping to that list, which the shipped H2 block is missing.((( | ||
| 31 | {{code language="xml"}} | ||
| 32 | <mapping resource="mailsender.hbm.xml"/> | ||
| 33 | {{/code}} | ||
| 34 | ))) | ||
| 35 | 1. Start or restart the application server. XWiki creates the database and its tables on the first run. | ||
| 36 | 1. Verify that the directory in the connection URL now holds the database file.((( | ||
| 37 | {{code language="none"}} | ||
| 38 | $ ls /path/to/permanent/directory/database | ||
| 39 | xwiki.mv.db | ||
| 40 | {{/code}} | ||
| 41 | ))) |