Rocket to the Cloud Fast with Roo

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.

Gunnar Hillert’s Blog explains this well.



Adding CloudFoundry Plugin to Maven

Thanks to Gunnar Hillert’s post, we can add to our project’s Maven pom.xml file the CloudFoundry Plugin.

<plugins>
  ...
  <plugin>
    <groupId>org.cloudfoundry</groupId>
    <artifactId>cf-maven-plugin</artifactId>
    <version>1.0.0.M1</version>
    <configuration>
      <server>mycloudfoundry-instance</server>
      <target>http://api.cloudfoundry.com</target>
      <url>${project.name}.cloudfoundry.com</url>
      <memory>256</memory>
    </configuration>
  </plugin>
  ...
</plugins>



Add CloudFoundry Credentials

Add credentials to our userhome/.m2/settings.xml

<servers>
  ...
  <server>
    <id>mycloudfoundry-instance</id>
    <username>you@mycompany.com</username>
    <password>n00n3w1llgu3ss</password>
  </server>
  ...
</servers>

To push (deploy) the code to CloudFoundry type mvn cf:push
For more plugin details type mvn cf:help


About Gordon

Technology enthusiast primarily focused on Java and Open Source projects. Spring Certified Professional and Trainer. http://twitter.com/gdickens http://linkedin.com/in/gordondickens http://github.com/gordonad
This entry was posted in Cloud, CloudFoundry, Java, Roo, Spring, Spring Data, Spring Roo and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>