This document discusses various ways to integrate Grails applications into enterprise environments and processes. It covers integration points such as build systems, dependency management, databases, deployment, and the Spring framework. Specific topics include using Maven or Ant for builds, handling legacy databases through custom ORM mappings or XML files, configuring data sources and dependencies, and leveraging Spring and plugins for enterprise features like messaging and web services. Overall, the document outlines Grails' flexibility in working with external systems and processes commonly found in enterprise applications.
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
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
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
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
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
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
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