25 January 2015

Grails on Openshift

I created a simple Grails application which makes it possible to store client data inside a MySQL database. I created this application since I want to learn more about GORM (Grails Object Relational Mapping).

I already tested the application in the internal server from Grails, but I wanted to deploy it to a remote server. So I created a development account on Openshift and there I created the following server:

  • Tomcat 7 (JBoss EWS 2.0)
  • MySQL 5.5
  • phpMyAdmin 4.0
The phpMyAdmin cartidge is not necessary for installing the Grails application on the server. But it is ideal for checking the data inside the MySQL database.

I created a new war-file for the grails application and deployed it to the Openshift server.

When creating the Openshift server I got a url for the MySQL database. But when I placed this URL inside the datasource the application did not work. I found an ip-address inside the phpMyAdmin and when I used that ip number inside the datasource at first it worked fine. But I discovered that the ip-address was changing so I had to find another way to connect to the MySQL database.

After searching the internet I found the following entries for the datasource.

def credentials = [

dataSource {
    dbCreate = "create-drop"
    driverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://${credentials.hostname}:${credentials.port}/${credentials.name}?useUnicode=yes&characterEncoding=UTF-8"
    username = credentials.username
    password = credentials.password
    pooled = true