SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
Grails in the Enterprise


                       Peter Ledbrook




Monday, 30 May 2011                              1
Integration Points

     • Build
     • Dependencies
     • Database
     • Deployment
     • Spring




                          2

Monday, 30 May 2011           2
Integration Points

     • Build
     • Dependencies
     • Database
     • Deployment
     • Spring




                          3

Monday, 30 May 2011           3
Build




                      4

Monday, 30 May 2011       4
Ant Integration

     • An Ant task built in (grails.ant.GrailsTask)
     • Template Ant build:
         grails integrate-with --ant
     • Uses Ivy for dependency management
     • Not compatible with Ant 1.8




                                                      5

Monday, 30 May 2011                                       5
6

Monday, 30 May 2011       6
Maven

     • Maven Grails Plugin:
          https://github.com/grails/grails-maven
     • Use Maven 2 to build Grails projects
     • Declare dependencies in POM
     • Works for both applications and plugins!
     • Integration test framework:
       https://github.com/grails/grails_maven_plugin_testing_tests




                                                                7

Monday, 30 May 2011                                                  7
Getting Started



                               mvn archetype-generate ...


                                      mvn initialize -Xmx256m
                                                   e.g.
                                                 -XX:MaxPermSize=256m

                                  Set MAVEN_OPTS


                      Optional: add ‘pom true’ to dependency DSL

                                                                   8

Monday, 30 May 2011                                                     8
Packaging Types

     • ‘war’
          – Must configure execution section
          – Works with plugins that depend on ‘war’
     • ‘grails-app’
          – Less configuration
     • ‘grails-plugin’
          – For plugins!




                                                      9

Monday, 30 May 2011                                       9
10

Monday, 30 May 2011        10
Maven & Grails Plugins




                      > grails release-plugin
                                ==
                          > mvn deploy


                                                11

Monday, 30 May 2011                                  11
Maven & Grails Plugins


          Either:

                      <dependency>
                       <groupId>org.grails.plugins<groupId>
                       <artifactId>hibernate</artifactId>
                       <type>grails-plugin</type>
                      </dependency>

                      Use ‘mvn deploy’ or Release plugin!
                      And ‘pom: false’

                                                              12

Monday, 30 May 2011                                                12
Maven & Grails Plugins


              Or:

                      grails.project.dependency.resolution = {
                        ...
                        plugins {
                            compile ":hibernate:1.3.6"
                        }
                        ...
                      }



                                                                 13

Monday, 30 May 2011                                                   13
Customise the Build

     • Create new commands in <proj>/scripts
     • Package the commands in a plugin!
     • Create <proj>/scripts/_Events.groovy
          – Interact with standard build steps
          – Add test types
          – Configure embedded Tomcat




                                                 14

Monday, 30 May 2011                                   14
What the future holds...

     • Grails 2.0 will move to Gradle
          – More powerful and more flexible
          – Standard, well documented API
          – Ant & Maven support




                                              15

Monday, 30 May 2011                                15
Integration Points

     • Build
     • Dependencies
     • Database
     • Deployment
     • Spring




                          16

Monday, 30 May 2011            16
Dependency DSL


           grails.project.dependency.resolution = {
             inherits "global"
             log "warn"
             repositories {
                 grailsHome()
                 mavenCentral()
                 mavenRepo "http://localhost:8081/..."
             }
             ...
           }


                                                         17

Monday, 30 May 2011                                           17
Dependency DSL


           grails.project.dependency.resolution = {
             inherits "global"
             log "warn"
             ...
             dependencies {
                 compile "org.tmatesoft.svnkit:svnkit:1.3.3"
                 test "org.gmock:gmock:0.8.1"
             }
             ...
           }


                                                               18

Monday, 30 May 2011                                                 18
Integration Points

     • Build
     • Dependencies
     • Database
     • Deployment
     • Spring




                          19

Monday, 30 May 2011            19
‘Legacy’ Databases

     • Grails can create a database from your domain model...
     • ...but what if you don’t own the database?
          – DBA determines structure
          – Company conventions
          – Existing ‘legacy’ database




                                                                20

Monday, 30 May 2011                                                  20
Option 1: Custom ORM mapping




            class Book {
               ...
               static mapping = {
                   table "books"
                   title type: "books"
                   author column: "author_ref"
               }
            }


                                                 21

Monday, 30 May 2011                                   21
Option 2: JPA annotations




      <?xml version='1.0' encoding='UTF-8'?>
      <!DOCTYPE ...>
      <hibernate-configuration>
        <session-factory>
           <mapping class="org.ex.Book"/>
           <mapping class="org.ex.Author"/>
           ...
        </session-factory>
      </hibernate-configuration>


                                               22

Monday, 30 May 2011                                 22
Option 3: Hibernate XML Mappings




      <?xml version='1.0' encoding='UTF-8'?>
      <!DOCTYPE ...>
      <hibernate-configuration>
        <session-factory>
           <mapping resource="org.ex.Book.hbm.xml"/>
           <mapping resource="org.ex.Author.hbm.xml"/>
           ...
        </session-factory>
      </hibernate-configuration>


                                                         23

Monday, 30 May 2011                                           23
Constraints


        Given domain class:

                  org.example.myapp.domain.Book

        Then:
                  src/java/org/example/myapp/domain/BookConstraints.groovy

          constraints = {
            title blank: false, unique: true
            ...
          }

                                                                             24

Monday, 30 May 2011                                                               24
Option 4: GORM JPA Plugin

     • GORM layer over JPA
     • Use your own JPA provider
     • Useful for cloud services that only work with JPA, not
       Hibernate




                                                                25

Monday, 30 May 2011                                                  25
Share your model!




                         26

Monday, 30 May 2011           26
Database Management

     • Hibernate auto-DDL
          – Good for dev & test
          – Bad for production!
     • Data migration
          – http://grails.org/plugin/database-migration
     • Reverse engineer a model
          – http://grails.org/plugin/db-reverse-engineer




                                                           27

Monday, 30 May 2011                                             27
Integration Points

     • Build
     • Dependencies
     • Database
     • Deployment
     • Spring




                          28

Monday, 30 May 2011            28
grails war

     • Build properties:
          – grails.war.copyToWebApp
          – grails.war.dependencies
          – grails.war.resources
          – grails.project.war.file




                                      29

Monday, 30 May 2011                        29
Control of JARs

           grails.project.dependency.resolution = {
             defaultDependenciesProvided true
             inherits "global"
             log "warn"
             ...
           }     grails war --nojars => WEB-INF/lib/<empty>
                      => No Grails JARs in WEB-INF/lib




                                                              30

Monday, 30 May 2011                                                30
Data Source

        JNDI:

               dataSource {
                 jndiName = "java:comp/env/myDataSource"
               }

        System property:

             dataSource {
               url = System.getProperty("JDBC_STRING")
             }

                                                           31

Monday, 30 May 2011                                             31
Data Source


       Config.groovy:

               grails.config.locations = [
                 "file:./${appName}-config.groovy",
                 "classpath:${appName}-config.groovy" ]


       For run-app:         ./<app>-config.groovy


       For Tomcat:          tomcat/lib/<app>-config.groovy


                                                             32

Monday, 30 May 2011                                               32
Integration Points

     • Build
     • Dependencies
     • Database
     • Deployment
     • Spring




                          33

Monday, 30 May 2011            33
Grails is Spring

     • Spring MVC under the hood
     • Grails provides many useful beans
          – e.g. grailsApplication
     • Define your own beans!
          – resources.xml/groovy
          – In a plugin




                                           34

Monday, 30 May 2011                             34
Example

      import ...
      beans = {
        credentialMatcher(Sha1CredentialsMatcher) {
           storedCredentialsHexEncoded = true
        }

           sessionFactory(ConfigurableLocalSessionFactoryBean) {
             dataSource = ref("dataSource")
             hibernateProperties = [
                  "hibernate.hbm2ddl.auto": "create-drop",
                  "hibernate.show_sql": true ]
           }
      }



                                                                   35

Monday, 30 May 2011                                                     35
Enterprise Integration

     • Spring opens up a world of possibilities
          – Spring Integration/Camel
          – Messaging (JMS/AMQP)
          – ESB
          – RMI, HttpInvoker, etc.
     • Web services & REST




                                                  36

Monday, 30 May 2011                                    36
Grails Plugins

     •   Routing
     •   JMS, RabbitMQ
     •   CXF, Spring-WS, WS-Client
     •   REST




                                     37

Monday, 30 May 2011                       37
Summary

     • Various options for integrating Grails with:
           – Development/build
           – Deployment processes
     • Works with many external systems
           – Solid support for non-Grailsy DB schemas
           – Flexible messaging & web service support




                                                        38

Monday, 30 May 2011                                          38
Thank you!




                      Q&A



                            39

Monday, 30 May 2011              39

Más contenido relacionado

Similar a GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook

GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook
GR8Conf 2011: Tuning Grails Applications by Peter LedbrookGR8Conf 2011: Tuning Grails Applications by Peter Ledbrook
GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook
GR8Conf
 
NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time Web
Jakub Nesetril
 

Similar a GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook (20)

GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook
GR8Conf 2011: Tuning Grails Applications by Peter LedbrookGR8Conf 2011: Tuning Grails Applications by Peter Ledbrook
GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook
 
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter LedbrookJava Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
 
Implementing Quality on Java projects
Implementing Quality on Java projectsImplementing Quality on Java projects
Implementing Quality on Java projects
 
Simple Build Tool
Simple Build ToolSimple Build Tool
Simple Build Tool
 
5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...
5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...
5 Thing You're Not Doing, 4 Things You Should Stop Doing & 3 Things You Shoul...
 
NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time Web
 
Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.
 
Gallio Crafting A Toolchain
Gallio Crafting A ToolchainGallio Crafting A Toolchain
Gallio Crafting A Toolchain
 
Webpack essentails - feb 19, 2020
Webpack essentails - feb 19, 2020Webpack essentails - feb 19, 2020
Webpack essentails - feb 19, 2020
 
Automating the Quality
Automating the QualityAutomating the Quality
Automating the Quality
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
 
Cloudops fundamentals management, tdd, test driven design, continuous integra...
Cloudops fundamentals management, tdd, test driven design, continuous integra...Cloudops fundamentals management, tdd, test driven design, continuous integra...
Cloudops fundamentals management, tdd, test driven design, continuous integra...
 
DevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation SlidesDevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation Slides
 
Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)
 
CI from scratch with Jenkins (EN)
CI from scratch with Jenkins (EN)CI from scratch with Jenkins (EN)
CI from scratch with Jenkins (EN)
 
Iteratively introducing Puppet technologies in the brownfield; Jeffrey Miller
Iteratively introducing Puppet technologies in the brownfield; Jeffrey MillerIteratively introducing Puppet technologies in the brownfield; Jeffrey Miller
Iteratively introducing Puppet technologies in the brownfield; Jeffrey Miller
 
Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)
 
Puppetconf 2015 - Puppet Reporting with Elasticsearch Logstash and Kibana
Puppetconf 2015 - Puppet Reporting with Elasticsearch Logstash and KibanaPuppetconf 2015 - Puppet Reporting with Elasticsearch Logstash and Kibana
Puppetconf 2015 - Puppet Reporting with Elasticsearch Logstash and Kibana
 
Pragmatische Plone Projekte
Pragmatische Plone ProjektePragmatische Plone Projekte
Pragmatische Plone Projekte
 
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
 

Más de GR8Conf

Más de GR8Conf (20)

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
 
Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle
 
Mum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerMum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developer
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with Geb
 
How to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidHow to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and Android
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the Docks
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature plugins
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applications
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3
 
Grails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGrails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloud
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEB
 
Deploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCDeploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPC
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshop
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spock
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem Revisited
 
Groovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGroovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examples
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and Groovy
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual Machine
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook

  • 1. Grails in the Enterprise Peter Ledbrook Monday, 30 May 2011 1
  • 2. Integration Points • Build • Dependencies • Database • Deployment • Spring 2 Monday, 30 May 2011 2
  • 3. Integration Points • Build • Dependencies • Database • Deployment • Spring 3 Monday, 30 May 2011 3
  • 4. Build 4 Monday, 30 May 2011 4
  • 5. Ant Integration • An Ant task built in (grails.ant.GrailsTask) • Template Ant build: grails integrate-with --ant • Uses Ivy for dependency management • Not compatible with Ant 1.8 5 Monday, 30 May 2011 5
  • 7. Maven • Maven Grails Plugin: https://github.com/grails/grails-maven • Use Maven 2 to build Grails projects • Declare dependencies in POM • Works for both applications and plugins! • Integration test framework: https://github.com/grails/grails_maven_plugin_testing_tests 7 Monday, 30 May 2011 7
  • 8. Getting Started mvn archetype-generate ... mvn initialize -Xmx256m e.g. -XX:MaxPermSize=256m Set MAVEN_OPTS Optional: add ‘pom true’ to dependency DSL 8 Monday, 30 May 2011 8
  • 9. Packaging Types • ‘war’ – Must configure execution section – Works with plugins that depend on ‘war’ • ‘grails-app’ – Less configuration • ‘grails-plugin’ – For plugins! 9 Monday, 30 May 2011 9
  • 10. 10 Monday, 30 May 2011 10
  • 11. Maven & Grails Plugins > grails release-plugin == > mvn deploy 11 Monday, 30 May 2011 11
  • 12. Maven & Grails Plugins Either: <dependency> <groupId>org.grails.plugins<groupId> <artifactId>hibernate</artifactId> <type>grails-plugin</type> </dependency> Use ‘mvn deploy’ or Release plugin! And ‘pom: false’ 12 Monday, 30 May 2011 12
  • 13. Maven & Grails Plugins Or: grails.project.dependency.resolution = { ... plugins { compile ":hibernate:1.3.6" } ... } 13 Monday, 30 May 2011 13
  • 14. Customise the Build • Create new commands in <proj>/scripts • Package the commands in a plugin! • Create <proj>/scripts/_Events.groovy – Interact with standard build steps – Add test types – Configure embedded Tomcat 14 Monday, 30 May 2011 14
  • 15. What the future holds... • Grails 2.0 will move to Gradle – More powerful and more flexible – Standard, well documented API – Ant & Maven support 15 Monday, 30 May 2011 15
  • 16. Integration Points • Build • Dependencies • Database • Deployment • Spring 16 Monday, 30 May 2011 16
  • 17. Dependency DSL grails.project.dependency.resolution = { inherits "global" log "warn" repositories { grailsHome() mavenCentral() mavenRepo "http://localhost:8081/..." } ... } 17 Monday, 30 May 2011 17
  • 18. Dependency DSL grails.project.dependency.resolution = { inherits "global" log "warn" ... dependencies { compile "org.tmatesoft.svnkit:svnkit:1.3.3" test "org.gmock:gmock:0.8.1" } ... } 18 Monday, 30 May 2011 18
  • 19. Integration Points • Build • Dependencies • Database • Deployment • Spring 19 Monday, 30 May 2011 19
  • 20. ‘Legacy’ Databases • Grails can create a database from your domain model... • ...but what if you don’t own the database? – DBA determines structure – Company conventions – Existing ‘legacy’ database 20 Monday, 30 May 2011 20
  • 21. Option 1: Custom ORM mapping class Book { ... static mapping = { table "books" title type: "books" author column: "author_ref" } } 21 Monday, 30 May 2011 21
  • 22. Option 2: JPA annotations <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE ...> <hibernate-configuration> <session-factory> <mapping class="org.ex.Book"/> <mapping class="org.ex.Author"/> ... </session-factory> </hibernate-configuration> 22 Monday, 30 May 2011 22
  • 23. Option 3: Hibernate XML Mappings <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE ...> <hibernate-configuration> <session-factory> <mapping resource="org.ex.Book.hbm.xml"/> <mapping resource="org.ex.Author.hbm.xml"/> ... </session-factory> </hibernate-configuration> 23 Monday, 30 May 2011 23
  • 24. Constraints Given domain class: org.example.myapp.domain.Book Then: src/java/org/example/myapp/domain/BookConstraints.groovy constraints = { title blank: false, unique: true ... } 24 Monday, 30 May 2011 24
  • 25. Option 4: GORM JPA Plugin • GORM layer over JPA • Use your own JPA provider • Useful for cloud services that only work with JPA, not Hibernate 25 Monday, 30 May 2011 25
  • 26. Share your model! 26 Monday, 30 May 2011 26
  • 27. Database Management • Hibernate auto-DDL – Good for dev & test – Bad for production! • Data migration – http://grails.org/plugin/database-migration • Reverse engineer a model – http://grails.org/plugin/db-reverse-engineer 27 Monday, 30 May 2011 27
  • 28. Integration Points • Build • Dependencies • Database • Deployment • Spring 28 Monday, 30 May 2011 28
  • 29. grails war • Build properties: – grails.war.copyToWebApp – grails.war.dependencies – grails.war.resources – grails.project.war.file 29 Monday, 30 May 2011 29
  • 30. Control of JARs grails.project.dependency.resolution = { defaultDependenciesProvided true inherits "global" log "warn" ... } grails war --nojars => WEB-INF/lib/<empty> => No Grails JARs in WEB-INF/lib 30 Monday, 30 May 2011 30
  • 31. Data Source JNDI: dataSource { jndiName = "java:comp/env/myDataSource" } System property: dataSource { url = System.getProperty("JDBC_STRING") } 31 Monday, 30 May 2011 31
  • 32. Data Source Config.groovy: grails.config.locations = [ "file:./${appName}-config.groovy", "classpath:${appName}-config.groovy" ] For run-app: ./<app>-config.groovy For Tomcat: tomcat/lib/<app>-config.groovy 32 Monday, 30 May 2011 32
  • 33. Integration Points • Build • Dependencies • Database • Deployment • Spring 33 Monday, 30 May 2011 33
  • 34. Grails is Spring • Spring MVC under the hood • Grails provides many useful beans – e.g. grailsApplication • Define your own beans! – resources.xml/groovy – In a plugin 34 Monday, 30 May 2011 34
  • 35. Example import ... beans = { credentialMatcher(Sha1CredentialsMatcher) { storedCredentialsHexEncoded = true } sessionFactory(ConfigurableLocalSessionFactoryBean) { dataSource = ref("dataSource") hibernateProperties = [ "hibernate.hbm2ddl.auto": "create-drop", "hibernate.show_sql": true ] } } 35 Monday, 30 May 2011 35
  • 36. Enterprise Integration • Spring opens up a world of possibilities – Spring Integration/Camel – Messaging (JMS/AMQP) – ESB – RMI, HttpInvoker, etc. • Web services & REST 36 Monday, 30 May 2011 36
  • 37. Grails Plugins • Routing • JMS, RabbitMQ • CXF, Spring-WS, WS-Client • REST 37 Monday, 30 May 2011 37
  • 38. Summary • Various options for integrating Grails with: – Development/build – Deployment processes • Works with many external systems – Solid support for non-Grailsy DB schemas – Flexible messaging & web service support 38 Monday, 30 May 2011 38
  • 39. Thank you! Q&A 39 Monday, 30 May 2011 39