Setting up a Grails app on Cloud Foundry

I was lucky enough to get access to cloud foundry. I have heard a lot about how easy it is to deploy a grails app on cloudfoundry. I had to try it myself and here is my experience trying to do so….

Building An App
Lets just create a simple grails app called “HelloCloudFoundry”. to do so, we can create a grails app by running the “grails create-app” command like follows:

   /home/manijshrestha/workspace/$grails create-app HelloCloudFoundry

Once the app is created lets just dummy up a index.gsp, I usally delete the default one grails creates and replace it with my own with body text “HelloWorld”. For this example I replaced the content of the index.gsp with simple html as follows

        <title>Hello Cloud Foundry</title>
        Hello From the Cloud!

Installing cloud foundry plugin
I was pretty impressed that grails already had a cloupowershellpowershelld foundry plugin, to install lets just run our typical grails install as follows

/home/manijshrestha/workspace/HelloCloudFoundry$ grails install-plugin cloud-foundry 

Now, it should install the plugin for cloudfoundry

Configuring the App
To set up the app its fairly easy, edit the Config.grooy file found in grails-app/conf/Config.groovy
and set up with your credentials. If you don’t have an account get one via
You should receive an email with user username and password

grails.plugin.cloudfoundry.username = ''
grails.plugin.cloudfoundry.password = 's3kr3t'
grails.plugin.cloudfoundry.appname = 'YOUR-APP-NAME'

thats it!!! we about 90 percent done!

Now, lets deploy our app!!! Yes we are there now..

Now lets just run a grails command to push the app to the cloud foundry

from the command line run

NOTE: technically, we should configure our database like mysql or mongodb etc, but for our demo we will just push it, the command will asks us to create one and we will do so.

   $grails prod cf-push

You will see some input dialogs asking you for the app url? and also since, we didn’t configure a service it will ask you if you would like to bind a mysql service, See my responses below:

Application Deployed URL: ''?

Would you like to bind the 'mysql-XXXX' service? ([y], n)

And BOOM we are done now you can navigate to your application URL
in my case its

Hopefully you enjoyed this, feel free to comment!

Helpful Links:


Mobile Development using FLEX!

Adobe air has been creating buzz about being able to develop flex application in multiple platform pretty similar to Java. Now, with Adobe Air being available in mobile devices, possibility is endless. It will be interesting to see how far this will go. Specially, the devices with lot of hardware like accelerometer, gyroscope, GPS. (Hello Apple, will you someone day support Adobe Air?Ans: No, If you want adobe use Android!)

Android SDK – Changing background of a layout at run time

I was working on a android project where I had to change background image in a layout at at run time. For instance, the user selects an image and it becomes the background of the layout. It is fairly simple to do in Android. See below on how I achieved it:

I have a Frame Layout in which I have defined a background in my case the image file name is “wooden.png” so I have, ‘ android:background=”@drawable/wooden” ‘ in the layout definition. By having this line in my layout, Android will use the wooden.png  that is in the “drawable” directory as the background for the activity .

See below for xml extract:

<FrameLayout xmlns:android=""	android:id="@+id/main_layout"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@drawable/wooden">

.. ...



In the code if I want to change the background I could achieve this by calling “setBackgroundResource” method on the layout.

See below for an example.


View mainLayout = findViewById(; // getting the layout

mainLayout.setBackgroundResource(R.drawable.stone); // changing the background to 'stone.png'