SlideShare a Scribd company logo
Groovy And Grails
Harshad Oak
Rightrix Solutions
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Groovy Basics
• Scripting / Agile / Dynamic ...Language
• Syntax very close to Java
• Meant for Java developers.
• A powerful high level language for the Java
“platform”
• Groovy code Compiles to Java bytecode.
• You can get productive quickly
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Groovy Basics
• Open source using a BSD / Apache style licence
• Backed by JSR 241
• groovy.codehaus.org
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Groovy Installation
• Download binary
• Set GROOVY_HOME
• Add GROOVY_HOME/bin to your PATH
• Set JAVA_HOME
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Groovy with Java
• Use groovyc just like javac to produce bytecode
files
• Groovy integrates with the Bean Scripting
Framework, which allows you to embed any
scripting engine into your Java code
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Closures
• Closures are reusable blocks of code
• One or more program statements enclosed in
curly brackets
• Closures do not require a class or a method
name
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Closures
• Can be passed around like a variable
• The statements within a closure are not
executed until the call() is made
• Return is using an explicit return statement or
the value of the last executed statement
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Dynamic Methods
• Adding new methods to an object at runtime
• Intercept non-existent method calls
• Used extensively in Grails
• Meta-Object Protocol
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Groovy Features
• Language Constructs
• List & Maps support
• XML Capabilities
• Swing Capabilities
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Groovlets and GSP
• Groovy alternatives for Servlets and JSP
• Will work on any J2EE container.
• Add JAR files
• Tweak web.xml
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Groovlets and GSP
• Implicit Variables
• request ServletRequest
• response ServletResponse -
• context ServletContext
• application ServletContext
• session getSession(false)
• out response.getWriter()
• sout response.getOutputStream()
• html new MarkupBuilder(out)
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails
• Web Framework inspired by Ruby On Rails
• Latest version is 0.2.1
• Coding by convention paradigm
• Reduce the need for configuration files and
other boilerplate code
• File names are important
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails
• Provides several commands to auto generate
common requirements in a web app.
• Based on open source technologies like Spring,
Hibernate and SiteMesh
• Grails hides underlying complexity
• Focus is on rapid development and simplicity
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Installation
• Extract contents
• Set GRAILS_HOME environment variable
• Add GRAILS_HOMEbin to the PATH variable
• Run the grails command from the command
prompt to check usage
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Application Structure
Controllers
Domain Classes
Views
Normal J2EE web
application
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
GORM
• Domain Classes are objects that are mapped to
the database
• Uses Hibernate 3 underneath
• Link domain classes using relationships
• Provide powerful dynamic methods for CRUD
(Create/Read/Update/Delete) operations
• An HSQL database comes built-in with Grails
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Development
• Example -Develop a Clothes Manager web
application
• Use MySQL database
•Setup DB
•Setup ApplicationDataSource
• Create Domain Classes
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Development - Domain
Classes
• Create Domain Classes
• Cabinet.groovy
• Shirt.groovy
• Trouser.groovy
• Define relationships
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Development
-Controllers
• Controllers are responsible for handling the
requests in the web application
• Use grails -generate-all to generate controllers
for our 3 domain classes
• Once controller is done processing a request, it
has to delegate to an appropriate view
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Development -Views
• Controllers delegate to view based on a
convention mechanism
• So list closure in ShirtController will delegate to
the view /grails-app/views/shirt/list.gsp or
/grails-app/views/shirt/list.jsp.
• Note that you can use JSPs
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Development -Deploy
• Built in Resin server
• Directly run your application by using the grails
run-app command
• Lets use Tomcat instead
• WAR file creation using grails war
• Deploy the WAR file just like any other J2EE
WAR file
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Custom View and
Controller
• Grails currently only auto generates views based
on a domain class
• Manually create a new view
• Edit web.xml for mapping the new view
• Deploy and try out on Tomcat
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Services
• Services are named in the format
XXService.groovy
• Directory /grails-app/services
• Can have Business Logic
• You can call these services from within
controllers
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails Tags
• Range of tags for both GSPs and JSPs
• No configuration
• No updating of TLD descriptors
• Edit grails-apptaglibApplicationTagLib.groovy
or create a new file XXTagLib.groovy
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails - Ajax
• Can work with Prototype, Yahoo or Dojo
• Configure the library and then just use the grails
tags
• Use render method to send text, markup, JSON
or OpenRico responses
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Grails
• Testing
• IDE Integration
• Validation
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06
Thank You
• Further Reading
• groovy.codehaus.org
• grails.org
• Several books in the works
• Groovy in Action (Manning)
• Groovy Programming: An Introduction for Java
Developers (Morgan Kaufmann)
Harshad Oak - harshad@rightrix.com

More Related Content

What's hot (20)

PDF
IPWB and IPFS at WAC2017
David Dias
 
PPTX
Semantics, rdf and drupal
Gokul Nk
 
PDF
Gatsby (Code.Talks) 2019
Stefan Adolf
 
PDF
Serverless Big Data Architecture on Google Cloud Platform at Credit OK
Kriangkrai Chaonithi
 
PDF
Integrating Drupal with a Triple Store
Barry Norton
 
PDF
Cassandra Summit 2015 - Building a multi-tenant API PaaS with DataStax Enterp...
Restlet
 
KEY
MongoDB SF Python
Mike Dirolf
 
PDF
Synchronization with CouchDB and PouchDB
EU Edge
 
PPTX
MongoDB and MongoMK Source Event
Yuval Ararat
 
PPT
Intro ror
tim_tang
 
PDF
Object data manager Tutorials
jivandip7
 
PDF
Scaling Redis: Dmitry Polyakovsky
Redis Labs
 
PDF
gVisor, Kata Containers, Firecracker, Docker: Who is Who in the Container Space?
ArangoDB Database
 
PPTX
Neo4j tms
_mdev_
 
PDF
Getting Started with Riak - NoSQL Live 2010 - Boston
Rusty Klophaus
 
KEY
Living with SQL and NoSQL at craigslist, a Pragmatic Approach
Jeremy Zawodny
 
PDF
Last Month in PHP - December 2015
Eric Poe
 
PDF
Batch import of large RDF datasets into Semantic MediaWiki
Samuel Lampa
 
PPTX
Yace 3.0
Atul Ashar
 
PDF
Introduction to RethinkDB and Horizon.js
chuck h
 
IPWB and IPFS at WAC2017
David Dias
 
Semantics, rdf and drupal
Gokul Nk
 
Gatsby (Code.Talks) 2019
Stefan Adolf
 
Serverless Big Data Architecture on Google Cloud Platform at Credit OK
Kriangkrai Chaonithi
 
Integrating Drupal with a Triple Store
Barry Norton
 
Cassandra Summit 2015 - Building a multi-tenant API PaaS with DataStax Enterp...
Restlet
 
MongoDB SF Python
Mike Dirolf
 
Synchronization with CouchDB and PouchDB
EU Edge
 
MongoDB and MongoMK Source Event
Yuval Ararat
 
Intro ror
tim_tang
 
Object data manager Tutorials
jivandip7
 
Scaling Redis: Dmitry Polyakovsky
Redis Labs
 
gVisor, Kata Containers, Firecracker, Docker: Who is Who in the Container Space?
ArangoDB Database
 
Neo4j tms
_mdev_
 
Getting Started with Riak - NoSQL Live 2010 - Boston
Rusty Klophaus
 
Living with SQL and NoSQL at craigslist, a Pragmatic Approach
Jeremy Zawodny
 
Last Month in PHP - December 2015
Eric Poe
 
Batch import of large RDF datasets into Semantic MediaWiki
Samuel Lampa
 
Yace 3.0
Atul Ashar
 
Introduction to RethinkDB and Horizon.js
chuck h
 

Viewers also liked (7)

PPTX
Median kanssa kasvamassa
anskuniskanen
 
ODP
Navarro fdz elena_gb_ing
Elena Navarro
 
PPTX
career options
Whiz Dom
 
PPT
Aquest soc jo
Carlos P. Jimenez
 
PPT
William’s workshops
William Doggen
 
PPT
Een serie
William Doggen
 
PPT
Part 1
William Doggen
 
Median kanssa kasvamassa
anskuniskanen
 
Navarro fdz elena_gb_ing
Elena Navarro
 
career options
Whiz Dom
 
Aquest soc jo
Carlos P. Jimenez
 
William’s workshops
William Doggen
 
Een serie
William Doggen
 
Ad

Similar to Groovy grailstutorial (20)

PPT
JavaOne 2008 - TS-5764 - Grails in Depth
Guillaume Laforge
 
ODP
Groovy and Grails intro
Miguel Pastor
 
POT
intoduction to Grails Framework
Harshdeep Kaur
 
PPTX
Introduction to Grails 2013
Gavin Hogan
 
PPTX
Magic with groovy & grails
George Platon
 
PDF
Groovy - Grails as a modern scripting language for Web applications
IndicThreads
 
PPT
Fast web development using groovy on grails
Anshuman Biswal
 
ODP
SVCC Intro to Grails
James Williams
 
ODP
Groovygrailsnetbeans 12517452668498-phpapp03
Kevin Juma
 
PDF
Grails 101
David Jacobs
 
ODP
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Sven Haiges
 
KEY
groovy & grails - lecture 9
Alexandre Masselot
 
PDF
Groovy and Grails
GiltTech
 
PDF
Grails 101
Lim Kin
 
PDF
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik
 
PDF
Groovy and Grails talk
desistartups
 
ODP
Agile web development Groovy Grails with Netbeans
Carol McDonald
 
PDF
Introduction To Groovy And Grails - SpringPeople
SpringPeople
 
PPT
Introduction to Grails
NexThoughts Technologies
 
PPT
Inrotograils 140211155206-phpapp01
Hiten Pratap Singh
 
JavaOne 2008 - TS-5764 - Grails in Depth
Guillaume Laforge
 
Groovy and Grails intro
Miguel Pastor
 
intoduction to Grails Framework
Harshdeep Kaur
 
Introduction to Grails 2013
Gavin Hogan
 
Magic with groovy & grails
George Platon
 
Groovy - Grails as a modern scripting language for Web applications
IndicThreads
 
Fast web development using groovy on grails
Anshuman Biswal
 
SVCC Intro to Grails
James Williams
 
Groovygrailsnetbeans 12517452668498-phpapp03
Kevin Juma
 
Grails 101
David Jacobs
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Sven Haiges
 
groovy & grails - lecture 9
Alexandre Masselot
 
Groovy and Grails
GiltTech
 
Grails 101
Lim Kin
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik
 
Groovy and Grails talk
desistartups
 
Agile web development Groovy Grails with Netbeans
Carol McDonald
 
Introduction To Groovy And Grails - SpringPeople
SpringPeople
 
Introduction to Grails
NexThoughts Technologies
 
Inrotograils 140211155206-phpapp01
Hiten Pratap Singh
 
Ad

Recently uploaded (20)

PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 

Groovy grailstutorial

  • 1. Groovy And Grails Harshad Oak Rightrix Solutions
  • 2. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Groovy Basics • Scripting / Agile / Dynamic ...Language • Syntax very close to Java • Meant for Java developers. • A powerful high level language for the Java “platform” • Groovy code Compiles to Java bytecode. • You can get productive quickly
  • 3. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Groovy Basics • Open source using a BSD / Apache style licence • Backed by JSR 241 • groovy.codehaus.org
  • 4. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Groovy Installation • Download binary • Set GROOVY_HOME • Add GROOVY_HOME/bin to your PATH • Set JAVA_HOME
  • 5. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Groovy with Java • Use groovyc just like javac to produce bytecode files • Groovy integrates with the Bean Scripting Framework, which allows you to embed any scripting engine into your Java code
  • 6. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Closures • Closures are reusable blocks of code • One or more program statements enclosed in curly brackets • Closures do not require a class or a method name
  • 7. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Closures • Can be passed around like a variable • The statements within a closure are not executed until the call() is made • Return is using an explicit return statement or the value of the last executed statement
  • 8. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Dynamic Methods • Adding new methods to an object at runtime • Intercept non-existent method calls • Used extensively in Grails • Meta-Object Protocol
  • 9. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Groovy Features • Language Constructs • List & Maps support • XML Capabilities • Swing Capabilities
  • 10. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Groovlets and GSP • Groovy alternatives for Servlets and JSP • Will work on any J2EE container. • Add JAR files • Tweak web.xml
  • 11. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Groovlets and GSP • Implicit Variables • request ServletRequest • response ServletResponse - • context ServletContext • application ServletContext • session getSession(false) • out response.getWriter() • sout response.getOutputStream() • html new MarkupBuilder(out)
  • 12. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails • Web Framework inspired by Ruby On Rails • Latest version is 0.2.1 • Coding by convention paradigm • Reduce the need for configuration files and other boilerplate code • File names are important
  • 13. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails • Provides several commands to auto generate common requirements in a web app. • Based on open source technologies like Spring, Hibernate and SiteMesh • Grails hides underlying complexity • Focus is on rapid development and simplicity
  • 14. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Installation • Extract contents • Set GRAILS_HOME environment variable • Add GRAILS_HOMEbin to the PATH variable • Run the grails command from the command prompt to check usage
  • 15. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Application Structure Controllers Domain Classes Views Normal J2EE web application
  • 16. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 GORM • Domain Classes are objects that are mapped to the database • Uses Hibernate 3 underneath • Link domain classes using relationships • Provide powerful dynamic methods for CRUD (Create/Read/Update/Delete) operations • An HSQL database comes built-in with Grails
  • 17. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Development • Example -Develop a Clothes Manager web application • Use MySQL database •Setup DB •Setup ApplicationDataSource • Create Domain Classes
  • 18. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Development - Domain Classes • Create Domain Classes • Cabinet.groovy • Shirt.groovy • Trouser.groovy • Define relationships
  • 19. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Development -Controllers • Controllers are responsible for handling the requests in the web application • Use grails -generate-all to generate controllers for our 3 domain classes • Once controller is done processing a request, it has to delegate to an appropriate view
  • 20. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Development -Views • Controllers delegate to view based on a convention mechanism • So list closure in ShirtController will delegate to the view /grails-app/views/shirt/list.gsp or /grails-app/views/shirt/list.jsp. • Note that you can use JSPs
  • 21. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Development -Deploy • Built in Resin server • Directly run your application by using the grails run-app command • Lets use Tomcat instead • WAR file creation using grails war • Deploy the WAR file just like any other J2EE WAR file
  • 22. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Custom View and Controller • Grails currently only auto generates views based on a domain class • Manually create a new view • Edit web.xml for mapping the new view • Deploy and try out on Tomcat
  • 23. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Services • Services are named in the format XXService.groovy • Directory /grails-app/services • Can have Business Logic • You can call these services from within controllers
  • 24. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails Tags • Range of tags for both GSPs and JSPs • No configuration • No updating of TLD descriptors • Edit grails-apptaglibApplicationTagLib.groovy or create a new file XXTagLib.groovy
  • 25. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails - Ajax • Can work with Prototype, Yahoo or Dojo • Configure the library and then just use the grails tags • Use render method to send text, markup, JSON or OpenRico responses
  • 26. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Grails • Testing • IDE Integration • Validation
  • 27. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06 Thank You • Further Reading • groovy.codehaus.org • grails.org • Several books in the works • Groovy in Action (Manning) • Groovy Programming: An Introduction for Java Developers (Morgan Kaufmann) Harshad Oak - [email protected]