groovy and grails - 123seminarsonly.com€¦ · groovy and grails in google app engine benefit from...

25
Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine Guillaume Laforge Head of Groovy Development

Upload: others

Post on 27-Apr-2020

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

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 Laforge

Head of Groovy Development

Page 2: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

2Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

• Groovy Project Manager

• JSR-241 Spec Lead

• Head of Groovy Developmentat 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

3Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

• 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

4Copyright 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

5Copyright 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

6Copyright 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

7Copyright 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

8Copyright 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

9Copyright 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

10Copyright 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

11Copyright 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

12Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

• 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 - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

13Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

From 10,000 feet...

13

QuickTime™ and aBMP decompressor

are needed to see this picture.

=

+ +

Page 14: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

14Copyright 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 15: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

15Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

The big picture

15

Page 16: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

16Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

The standard project structure

16

M

V

C

Page 17: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

17Copyright 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 18: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

18Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

Setting up your project

• Create your Grails application as usual•grails create-app myapp

• Specify the App Engine app id•google.appengine.application = "myapp"

• Uninstall hibernate and install the GAE plugin•grails uninstall-plugin hibernate

grails install-plugin app-engine

• Run the application locally•grails app-engine run

18

Page 19: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

19Copyright 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 ready•grails app-engine package

• On first deployment•$APPENGINE_HOME/appcfg.sh update ./target/war

• For subsequent deployments•grails app-engine deploy

19

Page 20: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

20Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 20

Page 21: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

21Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

• Groovy overview

–Features at a glance

–Groovlets

–Groovy templates

• Grails overview

–The Grails stack

–The App Engine plugin

• Summary

• Q&A

21

Page 22: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

22Copyright 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 23: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

23Copyright 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 24: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

24Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

• Groovy overview

–Features at a glance

–Groovlets

–Groovy templates

• Grails overview

–The Grails stack

–The App Engine plugin

• Summary

• Q&A

24

Page 25: Groovy and Grails - 123seminarsonly.com€¦ · Groovy and Grails in Google App Engine Benefit from a Java-like dynamic language to be more productive on App Engine ... •Grails

25Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

Q&A

• Questions & perhaps...

even answers :-)

25