Declare an XWiki Data Source in GlassFish

Last modified by Eleni Cojocariu on 2026/10/29 11:10

Steps

Warning

GlassFish is not an officially supported servlet container: these instructions are contributed by the community and receive no testing from the XWiki project.

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' \
      --isolationlevel read-committed \
      --maxpoolsize 50 \
      --statementcachesize 20 \
      jdbc/xwikipool

    The last three options are not tuning: they replace what XWiki's own pool was providing, which Use a Container-Managed Data Source explains. Left out, the isolation level is whatever the JDBC driver defaults to, and the statement cache size is 0, meaning no caching at all.

  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