Cloud Zone is brought to you in partnership with:

Gordon Dickens is an instructor, mentor & consultant. Gordon is currently architecting and teaching several official SpringSource courses and actively tweets about open source technology at http://twitter.com/gdickens. Gordon is active within the Spring Framework community focussed on: Spring training, Spring Roo, Spring Integration, Spring Batch and Eclipse Virgo OSGi projects. Gordon is a DZone MVB and is not an employee of DZone and has posted 39 posts at DZone. You can read more from them at their website. View Full User Profile

Rocket to the Cloud Fast with Roo

01.16.2013
| 1953 views |
  • submit to reddit

Want to build a Spring 3 application FAST and run it on the Cloud?

It is incredibly easy to do with Spring Roo and CloudFoundry!

This post on using Postgres on CloudFoundry helped me get started, however I tried using the 1.2.M1 with the CloudFoundry addon, but was unable to install it successfully in either 1.1.5.RELEASE or 1.2.0.M1.

Recently, Spring Roo moved to GitHub

Steps
  1. Get a Free CloudFoundry Account
  2. Clone the Spring Roo Git Repository
  3. Configure GPG/PGP setup
    see /spring-roo/readme.txt
  4. Build Spring Roo with Maven
    mvn -U clean install -Dgpg.passphrase=yourpassphrase
  5. Link the Roo startup script
    see /spring-roo/readme.txt
Creating a Project
  1. Make a directory for your SimpleItem project
    mkdir /SimpleItem
  2. Go to the directory
    cd /SimpleItem
  3. Create the script file simpleitem.roo in the /SimpleItem directory
    (see the contents below)
  4. Start roo-dev
  5. Type the command
    script --file simpleitem.roo
  6. Go To: http://mysimpleitem.cloudfoundry.com/
The simpleitem.roo script file
development mode --enabled true
project --topLevelPackage com.gordondickens.simpleitem --java 6 --projectName SimpleItem
jpa setup --provider HIBERNATE --database POSTGRES
entity --class ~.domain.Item --testAutomatically --activeRecord false
field string --fieldName name --sizeMin 3 --sizeMax 30 --class ~.domain.Item
field string --fieldName description --sizeMax 255 --class ~.domain.Item
field date --fieldName visitDate --type java.util.Date --notNull --past
repository jpa --interface ~.repository.ItemRepository --entity ~.domain.Item
service --interface ~.service.ItemService --entity ~.domain.Item

web mvc setup
web mvc all --package ~.web

logging setup --level DEBUG
perform package
download accept terms of use
pgp automatic trust

# ###########
# NOTE: Provide your credentials here, or perform these steps at the Roo prompt
# ###########
cloud foundry login --email you@mycompany.com --password n00n3w1llgu3ss

# ###########
# NOTE: The war file is the "--projectName" specified above
# ###########
cloud foundry deploy --appName mysimpleitem --path /target/SimpleItem-0.1.0.BUILD-SNAPSHOT.war --memory 512
cloud foundry create service --serviceName mysimpleitem-postgres --serviceType postgresql
cloud foundry bind service --serviceName mysimpleitem-postgres --appName mysimpleitem
cloud foundry start app --appName mysimpleitem

# ###########
# Go to URL: http://mysimpleitem.cloudfoundry.com/
NOTE CloudFoundry is Public

Since CloudFoundry is public, you may run into an issue deploying the application with the name above. You should change the --projectName to something unique with your name in it such as yourname-simpleitem.



Published at DZone with permission of Gordon Dickens, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)