Yey, I’m finally back!! This time I’ll share with you how to get Gerrit deployed on Glassfish application server and MySQL.
The pre-requisites are:
- MySQL up and running and experience creating databases and defining privileges;
- Glassfish up and running and the experience creating JDBC Datasources and deploying applications, including managing library dependencies for JDBC and others – in this case, you’ll need to provide MySQL JDBC driver and Bouncy Castle crypto API libraries to Gerrit.
If you’re ready, follow me now:
- Create a database for Gerrit
mysql -u root -p CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'secret'; CREATE DATABASE reviewdb; ALTER DATABASE reviewdb charset=latin1; GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost'; FLUSH PRIVILEGES;
- Download the latest version of Gerrit. By the time of this writing, it was 2.2.1.
- Initialize Gerrit in standalone mode (for now). Don’t forget to provide the correct MySQL configuration:
java -jar gerrit-2.2.1.war init -d gerrit
If all goes well, you should have a new directory named gerrit with everything you need to get Gerrit running. Also, the standalone server (Jetty) should be up. Stop it:
Now, let’s configure Glassfish datasource. Please, pay attention as this was where I got into problems..
- Create a JDBC Connection Pool with type javax.sql.DataSource and MySQL as datasource classname.
- Enable Ping mode.
- Define DatabaseName, User, Password, Server depending on what information you’ve provided while initializing Gerrit.
- Finally and most importantly, define both URL and Url properties to something like jdbc:mysql://localhost:3306/reviewdb?autoReconnect=true
- The parts in italic bold are the ones to change according to your own configuration.
Try to ping your datasource to check if it’s OK. It is? Great! Now, let’s proceed with the deployment of Gerrit:
asadmin deploy --contextroot codereview --name gerrit-2.2.1 gerrit-2.2.1.war
It should be working now! Point your browser to http://your_host/codereview, et voilá🙂