groovy and grails in google app engine
TRANSCRIPT
![Page 1: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/1.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Groovy and Grailsin Google App Engine
Benefit from a Java-like dynamic language to be more productive on App Engine
Guillaume LaforgeHead of Groovy Development
![Page 2: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/2.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
• Groovy Project Manager• JSR-241 Spec Lead• Head of Groovy Development
at SpringSource• Initiator of the Grails framework
• Co-author of Groovy in Action
• Speaker: JavaOne, QCon, JavaZone, Sun TechDays, Devoxx, The Spring Experience, JAX, Dynamic Language World, IJTC, and more...
Guillaume Laforge
2
![Page 3: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/3.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Agenda
•Groovy overview–Features at a glance–Groovlets–Groovy templates
• Grails overview–The Grails stack–The App Engine plugin
• Summary
• Q&A
3
![Page 4: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/4.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
A few words about Groovy
• Groovy is a dynamic language for the JVM–with a Meta Object Protocol–compiles directly to bytecode, seamless Java interop
• Open Source ASL 2 project hosted at Codehaus
• Relaxed grammar derived from Java 5–Java 5 features out-of-the-box: annotations, generics,
static imports, enums, varargs...–borrowed good ideas from Ruby, Python, Smalltalk–flat learning curve for Java developers
4
![Page 5: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/5.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Features at a glance
• Fully Object-Oriented• Joint compiler: seamless Java integration• Closures: reusable/assignable code blocks• Properties: no more getters / setters• Optional typing: you decide!• Various shortcut notations: less verbose than Java• Handy wrapper APIs
–Groovlets, XML, JDBC, JMX, template engine, Swing UIs, collections...
• Strong ability for authoring Domain-Specific Languages
5
![Page 6: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/6.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
A “normal” servlet
• Writing a servlet is no different than a classical standard Java servlet–only a bit leaner: properties, semis, public keyword...
• import javax.servlet.http.*
class HelloServlet extends HttpServlet { void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.contentType = "text/plain" resp.writer.println "Hello World!" }}
6
![Page 7: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/7.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Groovylets: Groovy servlets
• General idea–use scripts over classes–use Groovy’s markup builder to easily create HTML
• html.html { head { title "Hello" } body { p "Hello Groovy World!" }}
7
![Page 8: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/8.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Groovylets: Groovy servlets
• Refererence the GroovyServlet in web.xml• Add a URL mapping
• <servlet> <servlet-name>GroovyServlet</servlet-name> <servlet-class> groovy.servlet.GroovyServlet </servlet-class></servlet>
<servlet-mapping> <servlet-name>GroovyServlet</servlet-name> <url-pattern>*.groovy</url-pattern></servlet-mapping>
8
![Page 9: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/9.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Groovy templates
• Groovy comes built-in with templating capability
• import groovy.text.SimpleTemplateEngine
def text = '''Dear $firstname,So nice to meet you in <% print city %>.See you in ${month},<%= signed %>'''
def binding = [firstname: "Guillaume", month: "June", city: "San Francisco", signed: "Duke"]
def engine = new SimpleTemplateEngine()
template = engine.createTemplate(text) .make(binding)
9
![Page 10: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/10.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The Servlet template
• Similar to JSPs– <html> <body> <p>${message}</p> </body></html>
• In your web.xml– <servlet> <servlet-name>GroovyTemplateServlet</servlet-name> <servlet-class> groovy.servlet.TemplateServlet </servlet-class></servlet><servlet-mapping> <servlet-name>GroovyTemplateServlet</servlet-name> <url-pattern>*.gtpl</url-pattern></servlet-mapping>
10
![Page 11: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/11.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
• A thin layer on top of:–Groovlets & servlet template–Google App Engine Java SDK APIs
• What it does–Inject all the services in servlets and templates–Adds syntax sugar and dynamic methods to the SDK API
11
F GAELYK
![Page 12: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/12.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Agenda
• Groovy overview–Features at a glance–Groovlets–Groovy templates
•Grails overview–The Grails stack–The App Engine plugin
• Summary
• Q&A
12
![Page 13: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/13.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
From 10,000 feet...
13
=
![Page 14: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/14.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
From 10,000 feet...
13
=
![Page 15: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/15.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
From 10,000 feet...
13
=+
![Page 16: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/16.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
From 10,000 feet...
13
=+
![Page 17: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/17.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
From 10,000 feet...
13
=+ +
![Page 18: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/18.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
From 10,000 feet...
13
=+ +
![Page 19: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/19.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
In a few bullet points...
• Grails is a full stack web app development env.–built on rock-solid and proven OSS frameworks
•Spring, Spring MVC, Spring WebFlow•Hibernate, SiteMesh, Quartz•Jetty, HSQLDB
–provides its ORM layer on top of Hibernate–has got its own integrated build system and CLI
• Follows good and lean principles–Convention over Configuration, MVC, DRY...
• Provides powerful time-saving capabilities–Scaffolding, an extensible plugin system, taglibs,
templates, and more
14
![Page 20: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/20.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The big picture
15
The Java Virtual Machine
Groovy
Java Enterprise
Edition (JEE)Spring Hibernate SiteMesh
Grails
The Java LanguageThe Java Development
Kit (JDK)
![Page 21: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/21.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The big picture
15
The Java Virtual Machine
Groovy
Java Enterprise
Edition (JEE)Spring Hibernate SiteMesh
Grails
The Java LanguageThe Java Development
Kit (JDK)
![Page 22: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/22.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The standard project structure
16
M
V
C
![Page 23: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/23.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The App Engine plugin
• Grails has got a very extensive and rich plugin system and ecosystem–100+ existing and useful plugins available
•GWT, Flex, YUI, iUI, JMS, search, security, testing...
• A Google App Engine plugin was developed–following the Grails development flow–abstracts the app engine commands for deployments–leverages the local engine
17
![Page 24: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/24.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Setting up your project
• Create your Grails application as usualgrails create-app myapp
• Specify the App Engine app idgoogle.appengine.application = "myapp"
• Uninstall hibernate and install the GAE plugingrails uninstall-plugin hibernategrails install-plugin app-engine
• Run the application locallygrails app-engine run
18
![Page 25: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/25.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Deploying applications
• Set the version number to 1, as Grails uses a different numbering scheme (x.y)
grails set-version 1
• Get your application readygrails app-engine package
• On first deployment$APPENGINE_HOME/appcfg.sh update ./target/war
• For subsequent deploymentsgrails app-engine deploy
19
![Page 26: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/26.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
DEMO20
![Page 27: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/27.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Agenda
• Groovy overview–Features at a glance–Groovlets–Groovy templates
• Grails overview–The Grails stack–The App Engine plugin
•Summary
• Q&A
21
![Page 28: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/28.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Summary
• Groovy–Groovy is a first-class citizen on Google App Engine–Lots of shorcut notations can streamline your code–Groovy servlets and templates are great for crafting
small applications–Gaelyk further simplifies this pure Groovy approach
• Grails–Grails is the next-generation web development stack–Developing Grails application on the Google cloud is
almost as lean and simple as for the usual crop of application servers
22
![Page 29: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/29.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Further information
• Groovy in Google App Engine–http://blog.springsource.com/2009/04/07/write-your-
google-app-engine-applications-in-groovy/
• Grails in Google App Engine–the Grails 1.1.1 release and App Engine screencast
•http://blog.springsource.com/2009/05/14/grails-111-released-with-google-appengine-support/
–the Google App Engine Grails plugin•http://grails.org/plugin/app-engine
23
![Page 30: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/30.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Agenda
• Groovy overview–Features at a glance–Groovlets–Groovy templates
• Grails overview–The Grails stack–The App Engine plugin
• Summary
•Q&A
24
![Page 31: Groovy and Grails in Google App Engine](https://reader033.vdocuments.us/reader033/viewer/2022052618/554dbcc0b4c905c2488b49e3/html5/thumbnails/31.jpg)
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Q&A
• Questions & perhaps...
even answers :-)
25