Grails(12)Prepare My Working Environment

Grails(12)Prepare My Working Environment
Part One Obtaining Environment Tools
1. Prepare my github account
2. Setting up MySQL
3. Grails with old version 1.3.7
Download the old version 1.3.7 from here http://grails.org/download
Unzip the file and put in my working directory and ln a link to /opt

So right now, I have my grails on /opt/grails-1.3.7

4. I already installed the STS.
5. Set Up Grails
Follow this document and set up grails
http://grails.org/doc/1.3.7/guide/2.%20Getting%20Started.html#2.1 Downloading and Installing

>cd ~/
>vi .profile
export GRAILS_HOME=/opt/grails-1.3.7
export PATH=/opt/grails-1.3.7/bin:$PATH
>. .profile

But when I type command grails, I get error message
Error Messages:
Error opening zip file or JAR manifest missing : /opt/grails-1.3.7/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-1.0.6.jar
Error occurred during initialization of VM
agent library failed to init: instrument

Solution:
Maybe that is because my latest 2.1.0 version. I will uninstall my latest version first.
>sudo port uninstall grails @2.1.0_0
>grails help

And I type the command
>grails
I got the right version of 1.3.7.

6. STS Plug-in Acquisition
Dashboard ----> Grails Support and Groovy Eclipse

7. STS Grails Plug-in Set Up
References ----> Groovy ---> Grails ---->Add 1.3.7
And the groovy compile to 1.7

Part Two Setting Up My Workspace
1. Get all the project from github.

2. Set Up project Configuration

3. Importing Existing Projects
If there is not .project there in that project directory. Just create a new normal project on STS. Do not use import project.
>grails clean
>grails upgrade

And refresh the dependency in STS.

Finally, I successfully imported all the projects.

But my git can not fetch from remote from STS, I will fix that later.

4. Creating a User for the Database
Enter the mysql on my local machine
>mysql -uroot -p
mysql>create database sample;
mysql>grant all on sample.* to "username"@"localhost" identified by "111111";
mysql>exit;

Then login to the mysql with the newly created user and password.
>mysql -uusername -p111111

5.Upgrading Current Grails Application
upgrade all the grails project

6. Refresh Dependencies

7. Debugging
In STS, choose Debug Configurations ---> Create new in Grails and grails command
---> -DServer.port=9090 run-app

9. Creating Virtual Host
>vi /etc/hosts
Modify and find the virtual machine.

Part 3 Some Tips from Documents
2.6 Convention over Configuration
2.7 Running an Application
>grails -Dserver.port=9090 run-app

3. Configuration
3.1.3 GORM
3.7.2 Dependency Repositories
repositories {
     mavenCentral()
     ebr()
     mavenRepo "http://repository.some.org"
}

Local Directory
repositories {
     flatDir name:'myRepo', dirs: '/path/to/repo'
}

Local Maven repository ~/.m2/repository
repositories{    
     mavenLocal()
}

4. The Command Line
5. Object Relational Mapping(GORM)

Part 4 Groovy Review
Open groovy console
>groovyconsole

println "hello, Carl"

type <CTRL + R>

x = 1
println x
x = new java.util.Date()
println x

It seems that we do not have type for variables. So we can assign different value to them.

Lists and Maps
Built-in support for 2 data types, list for ordered collections of data.
myList = [12,-1,33,0]
println myList[1]
println myList.size()

Map is unordered collections
scores = ['carl': 168, 'kiko': 199]
println scores
println scores['carl']      //168
println scores.kiko     //199

And we can easily adding one product to map scores
scores['peter'] = 1000
println scores.peter

Empty the map
emptyMap = [:]
emptyList = []

Closures
square = { it * it}
println square(9)       // 81

newList = [1,3,4,5].collect(square)
println newList         // [1, 9, 16, 25]

By default closures take 1 parameter called "it". A closure for map.
printMap = {key, value -> println key + "=" + value }
['carl': 168, 'kiko': 199].each(printMap)

//carl=168
//kiko=199

Part 5 Error Messages
I had error message when I tried to fetch the source codes from github in STS.
Error Messages:
https://github.com/name/project: https://github.com/name/project/info/refs?service=git-upload-pack not found

Solution:
Then I go to the STS and git clone the project in Git Repository Exploring, that works.


References:
http://grails.org/doc/1.3.7/guide/2.%20Getting%20Started.html#2.1 Downloading and Installing
http://grails.org/doc/1.3.7/
http://grails.org/doc/1.3.7/guide/3.%20Configuration.html
http://sillycat.iteye.com/blog/830627
http://sillycat.iteye.com/blog/830631
http://groovy.codehaus.org/Getting+Started+Guide

你可能感兴趣的:(Environment)