- 浏览: 2552313 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Grails(4)Guide Book Chapter 4 Configuration and Command Line
4.7.2 Dependency Repositories
Remote Repositories
Initially your BuildConfig.groovy does not use any remote public Maven repositories. There is a default grailsHome() repository that will locate the JAR files Grails needs from my Grails installation. To configure a public repository, specify it in repositories block:
repositories {
mavenCentral() //maven center
ebr() //spring source enterprise bundle repository
}
we can also specify a specific URL
repositories{
mavenRepo name: "Codehaus", root: "http://repository.codehaus.org"
}
Controlling Repositories Inherited from Plugins
There is a flag for inherit
repositories{
inherit false
}
Offline Mode
There are times when it is not desirable to connect to any remote repositories(whilst working on the train for example)
>grails --offline run-app
Or do that in BuildConfig.groovy file:
grails.offline.mode=true
Local Resolvers
repositories {
flatDir name: 'myRepo', dirs: '/path/to/repo'
}
To specify my local Maven cache (~/.m2/repository) as a repository:
repositories {
mavenLocal()
}
Custom Resolvers
org.apache.ivy.plugins.resolver.URLResolver()
org.apache.ivy.plugins.resolver.SshResolver
Authentication
This can be placed in USER_HOME/.grails/settings.groovy file
grails.project.ivy.authentication = {
credentials {
realm = ".."
host = "localhost"
username = "user"
password = "111111"
}
}
4.7.3 Debugging Resolution
4.7.5 Providing Default Dependencies
Sometimes, the jar files will be provided by the container.
grails.project.dependency.resolution = {
defaultDependenciesProvided true // all of the default dependencies will
// be 'provided' by the container
…snip...
}
4.7.7 Dependency Reports
4.7.9 Maven Integration
grails.project.dependency.resolution = {
pom true
...
}
The line pom true tells Grails to parse Maven's pom.xml and load dependencies from there.
4.7.10 Deploying to a Maven Repository
>grails maven-install
>grails maven-deploy
4.7.11 Plugin Dependencies
grails.project.dependency.resolution = {
…
repositories {
}
plugins {
runtime ':hibernate:1.2.1'
}
dependencies{
}
}
Plugin Exclusions
plugins {
runtime(':weceem:0.8'){
excludes "searchable" //excludes most recent version
}
runtime ':searchable:0.5.4' //specifies a fixed searchable version
}
5. The Command Line
Grails' command line system is built on Gant - a simple Groovy wrapper around Apache ant.
Grails searches in the following directories for Gant scripts to execute:
USER_HOME/.gails/scripts
PROJECT_HOME/scripts
PROJECT_HOME/plugins/*/scripts
GRAILS_HOME/scripts
Grails will also convert command names that are in lower case.
>grails run-app
This command will look for RunApp.groovy.
From my understanding, seldom, we need some configuration.
>export GRAILS_OPTS="-Xmx1G -Xms256m -XX:MaxPermSize=256m"
>grails run-app
5.1 Interactive Mode
>grails
Enter interactive mode, then we can get a lot of help when we type tab button.
grails>
If we want to run an external process whilst interactive mode is running. We can do so by starting the command with !
grails>!ls
that will list all the file under this directory.
!ls !pwd some commands are working, for example, !cd is not working.
5.2 Forked Tomcat Execution
Grails 2.2 and above
5.3 Creating Gant Scripts
We can create our own Gant scripts by running the create-script command.
>grails create-script compile-sources
That will create a script called scripts/CompileSources.groovy
5.4 Re-using Grails scripts
includeTargets << grailsScript("_GrailsBootstrap")
includeTarget << new File("/path/to/my/own/script.groovy")
5.5 Hooking into Events
Event handlers are defined in scripts called _Events.groovy
5.6 Customizing the build
5.7 Ant and Maven
Ant Integration
>grails integrate-with --ant
Maven Integration
If my project named hellosillycat
>cd hellosillycat
>grails create-pom com.sillycat
5.8 Grails Wrapper
Generating The Wrapper
build the project with install grails
>grails wrapper
Using The Wrapper
./grailsw create-domain-class com.sillycat.Person
./grailsw run-app
6. Object Relational Mapping(GORM)
6.1 Quick Start Guide
A domain class can be created with the create-domain-class command
>grails create-domain-class hello world.Person
We can customize the class by adding properties:
class Person {
String name
Integer age
Date lastVist
}
6.1.1 Basic CRUD(Create/Read/Update/Delete)
Create
def p = new Person(name: "Carl", age: 30, lastVisit: new Date())
p.save()
Read
def p = Person.get(1)
assert 1 == p.id
Grails transparently adds an implicit id property to your domain class which you can use for retrieval.
We can also read the Person object back from the database
def p = Person.read(1)
This incurs no database access until a method other than getId(0 is called. That is to say, lazy load
def p = Person.load(1)
Update
Update some properties, then call save method
def p = Person.get(1)
p.name = "Kiko"
p.save()
Delete
def p = Person.get(1)
p.delete()
6.2 Domain Modeling in GORM
6.2.1 Association in GORM
6.2.1.1 Many-to-one and one-to-one
6.2.1.2 One-to-many
class Author {
static hasMany = [Books: Book]
String name
}
class Book {
static belongsTo = [author: Author]
String title
}
6.2.1.3 Many-to-many
class Book{
static belongsTo = Author
static hasMany = [authors:Author]
String title
}
class Author{
static hasMany = [books:Book]
String name
}
6.2.4 Sets, Lists and Maps
Sets of Objects
static hasMany = [books: Book]
It is a java.util.Set. Sets guarantee uniqueness but not order.
If we need order, we need to implement java.lang.Comparable. And define SortedSet
class Author {
SortedSet books
static hasMany = [books: Book]
}
class Book implements Comparable {
String title
Date releaseDate = new Date()
int compareTo(obj) {
releaseDate.compareTo(obj.releaseDate)
}
}
Lists of Objects
class Author {
List books
static hasMany = [books: Book]
}
Bags of Objects
class Author {
Collection books
static hasMany = [books: Book]
}
Maps of Objects
class Author {
Map books
}
def a = new Author()
a.books = ["key number“: "book name"]
References:
http://grails.org/doc/latest/guide/conf.html#dependencyRepositories
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/commandLine.html
http://grails.org/doc/latest/guide/GORM.html
4.7.2 Dependency Repositories
Remote Repositories
Initially your BuildConfig.groovy does not use any remote public Maven repositories. There is a default grailsHome() repository that will locate the JAR files Grails needs from my Grails installation. To configure a public repository, specify it in repositories block:
repositories {
mavenCentral() //maven center
ebr() //spring source enterprise bundle repository
}
we can also specify a specific URL
repositories{
mavenRepo name: "Codehaus", root: "http://repository.codehaus.org"
}
Controlling Repositories Inherited from Plugins
There is a flag for inherit
repositories{
inherit false
}
Offline Mode
There are times when it is not desirable to connect to any remote repositories(whilst working on the train for example)
>grails --offline run-app
Or do that in BuildConfig.groovy file:
grails.offline.mode=true
Local Resolvers
repositories {
flatDir name: 'myRepo', dirs: '/path/to/repo'
}
To specify my local Maven cache (~/.m2/repository) as a repository:
repositories {
mavenLocal()
}
Custom Resolvers
org.apache.ivy.plugins.resolver.URLResolver()
org.apache.ivy.plugins.resolver.SshResolver
Authentication
This can be placed in USER_HOME/.grails/settings.groovy file
grails.project.ivy.authentication = {
credentials {
realm = ".."
host = "localhost"
username = "user"
password = "111111"
}
}
4.7.3 Debugging Resolution
4.7.5 Providing Default Dependencies
Sometimes, the jar files will be provided by the container.
grails.project.dependency.resolution = {
defaultDependenciesProvided true // all of the default dependencies will
// be 'provided' by the container
…snip...
}
4.7.7 Dependency Reports
4.7.9 Maven Integration
grails.project.dependency.resolution = {
pom true
...
}
The line pom true tells Grails to parse Maven's pom.xml and load dependencies from there.
4.7.10 Deploying to a Maven Repository
>grails maven-install
>grails maven-deploy
4.7.11 Plugin Dependencies
grails.project.dependency.resolution = {
…
repositories {
}
plugins {
runtime ':hibernate:1.2.1'
}
dependencies{
}
}
Plugin Exclusions
plugins {
runtime(':weceem:0.8'){
excludes "searchable" //excludes most recent version
}
runtime ':searchable:0.5.4' //specifies a fixed searchable version
}
5. The Command Line
Grails' command line system is built on Gant - a simple Groovy wrapper around Apache ant.
Grails searches in the following directories for Gant scripts to execute:
USER_HOME/.gails/scripts
PROJECT_HOME/scripts
PROJECT_HOME/plugins/*/scripts
GRAILS_HOME/scripts
Grails will also convert command names that are in lower case.
>grails run-app
This command will look for RunApp.groovy.
From my understanding, seldom, we need some configuration.
>export GRAILS_OPTS="-Xmx1G -Xms256m -XX:MaxPermSize=256m"
>grails run-app
5.1 Interactive Mode
>grails
Enter interactive mode, then we can get a lot of help when we type tab button.
grails>
If we want to run an external process whilst interactive mode is running. We can do so by starting the command with !
grails>!ls
that will list all the file under this directory.
!ls !pwd some commands are working, for example, !cd is not working.
5.2 Forked Tomcat Execution
Grails 2.2 and above
5.3 Creating Gant Scripts
We can create our own Gant scripts by running the create-script command.
>grails create-script compile-sources
That will create a script called scripts/CompileSources.groovy
5.4 Re-using Grails scripts
includeTargets << grailsScript("_GrailsBootstrap")
includeTarget << new File("/path/to/my/own/script.groovy")
5.5 Hooking into Events
Event handlers are defined in scripts called _Events.groovy
5.6 Customizing the build
5.7 Ant and Maven
Ant Integration
>grails integrate-with --ant
Maven Integration
If my project named hellosillycat
>cd hellosillycat
>grails create-pom com.sillycat
5.8 Grails Wrapper
Generating The Wrapper
build the project with install grails
>grails wrapper
Using The Wrapper
./grailsw create-domain-class com.sillycat.Person
./grailsw run-app
6. Object Relational Mapping(GORM)
6.1 Quick Start Guide
A domain class can be created with the create-domain-class command
>grails create-domain-class hello world.Person
We can customize the class by adding properties:
class Person {
String name
Integer age
Date lastVist
}
6.1.1 Basic CRUD(Create/Read/Update/Delete)
Create
def p = new Person(name: "Carl", age: 30, lastVisit: new Date())
p.save()
Read
def p = Person.get(1)
assert 1 == p.id
Grails transparently adds an implicit id property to your domain class which you can use for retrieval.
We can also read the Person object back from the database
def p = Person.read(1)
This incurs no database access until a method other than getId(0 is called. That is to say, lazy load
def p = Person.load(1)
Update
Update some properties, then call save method
def p = Person.get(1)
p.name = "Kiko"
p.save()
Delete
def p = Person.get(1)
p.delete()
6.2 Domain Modeling in GORM
6.2.1 Association in GORM
6.2.1.1 Many-to-one and one-to-one
6.2.1.2 One-to-many
class Author {
static hasMany = [Books: Book]
String name
}
class Book {
static belongsTo = [author: Author]
String title
}
6.2.1.3 Many-to-many
class Book{
static belongsTo = Author
static hasMany = [authors:Author]
String title
}
class Author{
static hasMany = [books:Book]
String name
}
6.2.4 Sets, Lists and Maps
Sets of Objects
static hasMany = [books: Book]
It is a java.util.Set. Sets guarantee uniqueness but not order.
If we need order, we need to implement java.lang.Comparable. And define SortedSet
class Author {
SortedSet books
static hasMany = [books: Book]
}
class Book implements Comparable {
String title
Date releaseDate = new Date()
int compareTo(obj) {
releaseDate.compareTo(obj.releaseDate)
}
}
Lists of Objects
class Author {
List books
static hasMany = [books: Book]
}
Bags of Objects
class Author {
Collection books
static hasMany = [books: Book]
}
Maps of Objects
class Author {
Map books
}
def a = new Author()
a.books = ["key number“: "book name"]
References:
http://grails.org/doc/latest/guide/conf.html#dependencyRepositories
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/commandLine.html
http://grails.org/doc/latest/guide/GORM.html
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 478NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 424Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 248GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 452GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 319Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 312Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 288NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 261Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 574NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 266Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 368Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 370Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
《Grails 2 的终极指南》是一本深入探讨Grails框架精髓的专业书籍,该书以英文撰写,旨在为读者提供全面、深入的Grails框架学习资料。Grails框架基于Groovy语言,是一种高度动态、敏捷的Java应用开发框架,它简化了...
《The Definitive Guide to Grails 2》是Grails框架深入学习的重要参考资料,由业界专家撰写,旨在为开发者提供全面、详尽的Grails 2技术指导。这本书结合了理论与实践,不仅介绍了Grails的基本概念,还涵盖了高级...
Using the principle of convention-over-configuration and the dynamic Groovy programming language, Grails takes the pain out of web development and brings back the fun. This book will get you up and ...
Grails的自动化工具如命令行接口(Command Line Interface, CLI)也会被提及,它是快速搭建项目的关键。 第二篇笔记可能涉及Grails的领域模型(Domain Model),这是Grails中的核心组件,用于描述业务对象和它们...
6. **Command-line工具**:Grails命令行工具用于项目初始化、运行、测试等操作,是日常开发中的得力助手。 API部分,"grails-API-1.0"提供了Grails 1.0核心库的详细接口说明,包括核心类、方法和属性。这为开发者...
Groovy / Grails F4 The Best Web Server
4. **命令行工具**:Grails 提供强大的命令行工具,支持创建项目、运行应用、生成代码等任务,大大提升了开发效率。 5. **构建工具**:Grails 使用Gradle作为其构建工具,允许自定义构建流程和依赖管理。 **Grails...
4. **Grails Command Line Interface (CLI)**:强大的命令行工具,允许快速创建项目、生成代码、运行测试和部署应用。 **二、核心概念** 1. **Controllers**:负责处理HTTP请求,调用服务层方法,准备数据,并将...
在Grails框架中,GORM(Groovy Object Relational Mapping)是用于数据库操作的重要部分,它简化了对象与数据库表之间的映射。在本教程中,我们将深入探讨如何使用GORM处理1:M(一对一到多)关系。教程中提到的项目...
4. **参与社区**:加入 Grails 社区,与其他开发者交流心得,获取最新的技术动态。 《Grails 完全指南》不仅是一本学习资料,更是一份宝贵的资源,它帮助开发者全面掌握 Grails 框架,从而在 Java Web 开发领域取得...
**Grails Command Line Interface (CLI)** Grails 提供了一个强大的命令行工具,用于初始化项目、创建域类、生成控制器、运行测试等。这大大提高了开发效率,减少了手动编写配置文件的工作。 **Testing** Grails ...
4. **创建Grails项目**:现在,你可以通过Eclipse的"New" -> "Grails Project"来创建一个新的Grails项目。选择合适的Grails版本和其他配置,然后Eclipse会自动生成项目结构。 5. **开发与调试**:在Eclipse中,你...
4. **Grails命令行工具**:Grails提供了强大的命令行工具,用于项目初始化、创建控制器、服务、域类等。这些命令极大地简化了开发流程,使得开发者可以快速生成符合约定的代码结构。 5. **插件系统**:Grails的插件...
1. **Command Line Interface (CLI)**:Grails的命令行接口是开发者与框架交互的主要方式,`Main`类是入口点,负责解析命令行参数并调用相应的命令处理器。 2. **Bootstrap**:在Grails应用启动时,`Bootstrap`类...
grails1.0开发框架4 类似于ruby on rails的框架。
4. **Grails命令行工具**:提供了一系列的命令,如`generate-all`用于自动生成控制器、视图和模型类,极大地提高了开发效率。 5. **Grails插件系统**:Grails拥有庞大的插件库,涵盖各种功能,如安全、缓存、报表、...
Definitive Guide to Grails
4. **Grails Command Line Interface (CLI)**: Grails 3.3.2 包含了强大的命令行工具,允许开发者快速创建项目、运行测试、构建应用等。这极大地提高了开发效率,减少了手动配置的时间。 5. **Grails Plugins**: ...