GlassFish Installation

Last modified by Thomas Mortagne on 2023/10/10

XWiki doesn't work on GlassFish versions 3.1.2 and 3.1.2.1 due to a bug which affects file uploads.

We've had reports that recent versions of GlassFish don't work out of the box to deploy XWiki. We're looking for some GlassFish expert who could update the instructions below to make XWiki deploy fine in GlassFish. Thx.

  • Download the latest GlassFish
  • Download the exe for Windows or the shell script for Unix
  • Start GlassFish instance using $GLASSFISH_HOME/bin/asadmin start-domain
  • Do you want to deploy from the web interface, or the commandline?
  • Deploying from the web interface:
    • point your browser to http://localhost:4848
    • log in as the default administrator user admin with the default password adminadmin
    • select Applications -> Web Applications -> Deploy in the left tree
    • select the XWiki WAR archive to deploy and set the context root to xwiki (anything else will make XWiki navigation break)
  • Deploy from the commandline:
    • $GLASSFISH_HOME/bin/asadmin deploy --contextroot xwiki file.war
  • enjoy XWiki from http://localhost:8080/xwiki

If you need more help you can use the GlassFish documentation.

Configuring a MySQL datasource in Glassfish

  • Download the MySQL jdbc driver
  • Extract the contents of the file
  • Copy the jar file to GLASSFISH_HOME/glassfish/lib if you want it to be available to all Glassfish applications, or to the WEB-INF/lib dir of the XWiki deployment dir if you only want it to be available locally (example: GLASSFISH_HOME/glassfish/domains/domain1/applications/xwiki-enterprise-web-2.5-milestone-1/WEB-INF/lib)
  • Start or restart the Glassfish server: bin/asadmin start-domain or bin/asadmin restart-domain

If you want to use the web interface to define a datasource, you can read this tutorial on Creating and configuring a MySQL DataSource in GlassFish Application Server.

If you want to use the command line interface to define a datasource, you can read this tutorial.

Quick and dirty is easy:

  • Create the connection pool: Assuming you followed the MySQL Installation steps you have a MySQL database called 'xwiki' accessible with a user named 'xwiki' having 'xwiki' as the password.
  • asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
    --restype javax.sql.ConnectionPoolDataSource --property "User=xwiki:Password=xwiki:URL=jdbc\\:mysql\\://localhost\\:3306/xwiki"
    jdbc/xwikipool
  • This should give you Command create-jdbc-connection-pool executed successfully.
  • Test the connection pool: asadmin ping-connection-pool jdbc/xwikipool 
  • This should give you Command ping-connection-pool executed successfully.
  • If not, just execute bin/asadmin delete-jdbc-connection-pool jdbc/xwikipool and start again :-)
  • Create the JDBC resource: asadmin --user=admin create-jdbc-resource --connectionpoolid jdbc/xwikipool jdbc/xwiki
  • This should give you Command create-jdbc-resource executed successfully.
  • Test the JDBC resource: asadmin --user admin list-jdbc-resources 
  • This should result in:
    jdbc/__TimerPool
    jdbc/__default
    jdbc/xwiki

    Command list-jdbc-resources executed successfully.

Now the last thing you need to do is go into the directory glassfish/domains/domain1/applications/xwiki-enterprise-web-2.5-milestone-1/WEB-INF and edit hibernate.cfg.xml.

Uncomment the default database section (simpy by moving the "-->" part a couple of lines down), and uncomment the MySQL part.

Done!

Troubleshooting

First thing you would normally do is import the default xar file to initialize the wiki and populate it with some nice pages.
However, it is very likely that you will see an error message like: 

com.xpn.xwiki.XWikiException: Error number 0 in 11: Uncaught exception
Wrapped Exception: org.apache.commons.codec.binary.Base64.<init>(I[B)V

As explained in this email you should copy commons-codec-1.4.jar from the xwiki/WEB-INF/lib directory  to the glassfishv3/glassfishmodules and also delete commons-codec-repackaged.jar from the glassfishv3/glassfish/modules folder.

These steps should solve the problem.

Get Connected