Declare an XWiki Data Source in GlassFish

Last modified by Eleni Cojocariu on 2026/10/28 16:57

Steps

Create the jdbc/xwiki data source that Use a Container-Managed Data Source asks for, so that GlassFish opens XWiki's database connections instead of XWiki opening them itself. The commands below use MySQL.

  1. Copy the MySQL JDBC driver into GLASSFISH_HOME/glassfish/domains/domain1/lib, and not into the web application's WEB-INF/lib, so that GlassFish itself can load it. GlassFish picks it up without a restart since version 7.0.18; on an earlier release, restart the domain with asadmin restart-domain.
  2. Create the connection pool. Quote the property list and escape every colon inside it with a backslash, since asadmin reads the colon as its property separator:
    GLASSFISH_HOME/bin/asadmin create-jdbc-connection-pool \
      --datasourceclassname com.mysql.cj.jdbc.MysqlConnectionPoolDataSource \
      --restype javax.sql.ConnectionPoolDataSource \
      --property 'User=xwiki:Password=xwiki:URL=jdbc\:mysql\://localhost\:3306/xwiki' \
      jdbc/xwikipool
  3. Check that the pool reaches the database:
    GLASSFISH_HOME/bin/asadmin ping-connection-pool jdbc/xwikipool

    It answers Command ping-connection-pool executed successfully. If it fails instead, delete the pool with asadmin delete-jdbc-connection-pool jdbc/xwikipool and create it again with corrected values.

  4. Create the JDBC resource, naming it jdbc/xwiki:
    GLASSFISH_HOME/bin/asadmin create-jdbc-resource --connectionpoolid jdbc/xwikipool jdbc/xwiki
  5. List the resources:
    GLASSFISH_HOME/bin/asadmin list-jdbc-resources

    jdbc/xwiki appears beside GlassFish's own jdbc/__TimerPool and jdbc/__default. Point XWiki at it by following Use a Container-Managed Data Source.

FAQ

Does XWiki need a container-managed data source?

No. XWiki opens its own connections from WEB-INF/hibernate.cfg.xml, and the resource-ref element a container data source needs is commented out in WEB-INF/web.xml.

XWiki does not find the data source. What is wrong?

A java:comp/env name resolves only for a resource declared as a resource-ref in WEB-INF/web.xml. Either uncomment the one XWiki ships and match its res-ref-name, or set hibernate.connection.datasource to the global name jdbc/xwiki.

Related

Get Connected