首先,讓我們來搭建起開發Grails的環境。在Windows平臺下,他的配置和Java的環境十分相似,那我們一步一步開始吧!
一、下載最新的發布版本:http://www.grails.org.解壓后備用。本人把解壓后的文件置于Grooy目錄下。(以后的開發都在Groovy目錄下完成,最好再建個目錄projects)
二、設置GRAILS_HOME環境變量,類似于Java環境變量,找到解壓后的根目錄,如:E:\Groovy\grails-1.0.4
三、將GRAILS_HOME加入到PATH中,%GRAILS_HOME%/bin
OK,現在測試一下,命令行下輸入grails,如圖:
好了,準備工作就緒,讓我們開始介紹幾個簡單的命令吧!
命令行下輸入grails help,先來看看grails的基本命令吧
1
C:\>grails help
2
3
Welcome to Grails 1.0.4 - http://grails.org/
4
Licensed under Apache Standard License 2.0
5
Grails home is set to: E:\Groovy\grails-1.0.4
6
7
Base Directory: C:\
8
Note: No plugin scripts found
9
Running script E:\Groovy\grails-1.0.4\scripts\Help.groovy
10
Environment set to development
11
12
Usage (optionals marked with *):
13
grails [environment]* [target] [arguments]*
14
15
Examples:
16
grails dev run-app
17
grails create-app books
18
19
Available Targets (type grails help 'target-name' for more info):
20
grails bootstrap
21
grails bug-report
22
grails clean
23
grails compile
24
grails console
25
grails create-app
26
grails create-controller
27
grails create-domain-class
28
grails create-filters
29
grails create-integration-test
30
grails create-plugin
31
grails create-script
32
grails create-service
33
grails create-tag-lib
34
grails create-unit-test
35
grails doc
36
grails generate-all
37
grails generate-controller
38
grails generate-views
39
grails help
40
grails init
41
grails install-plugin
42
grails install-templates
43
grails list-plugins
44
grails package
45
grails package-plugin
46
grails plugin-info
47
grails release-plugin
48
grails run-app
49
grails run-app-https
50
grails run-war
51
grails set-proxy
52
grails set-version
53
grails shell
54
grails stats
55
grails test-app
56
grails upgrade
57
grails war
前面是命令格式介紹,后面從20-57行總共38條命令,在應用中會逐一介紹。
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

其中,應用創建命令grails create-app最為常用,它會為我們創建一個標準的規范化的grails應用框架目錄。如圖,
1
E:\Groovy\projects>grails create-app hello
2
3
Welcome to Grails 1.0.4 - http://grails.org/
4
Licensed under Apache Standard License 2.0
5
Grails home is set to: E:\Groovy\grails-1.0.4
6
7
Base Directory: E:\Groovy\projects
8
Note: No plugin scripts found
9
Running script E:\Groovy\grails-1.0.4\scripts\CreateApp.groovy
10
Environment set to development
11
[mkdir] Created dir: E:\Groovy\projects\hello\src
12
[mkdir] Created dir: E:\Groovy\projects\hello\src\java
13
[mkdir] Created dir: E:\Groovy\projects\hello\src\groovy
14
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app
15
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\controllers
16
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\services
17
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\domain
18
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\taglib
19
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\utils
20
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\views
21
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\views\layouts
22
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\i18n
23
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\conf
24
[mkdir] Created dir: E:\Groovy\projects\hello\test
25
[mkdir] Created dir: E:\Groovy\projects\hello\test\unit
26
[mkdir] Created dir: E:\Groovy\projects\hello\test\integration
27
[mkdir] Created dir: E:\Groovy\projects\hello\scripts
28
[mkdir] Created dir: E:\Groovy\projects\hello\web-app
29
[mkdir] Created dir: E:\Groovy\projects\hello\web-app\js
30
[mkdir] Created dir: E:\Groovy\projects\hello\web-app\css
31
[mkdir] Created dir: E:\Groovy\projects\hello\web-app\images
32
[mkdir] Created dir: E:\Groovy\projects\hello\web-app\META-INF
33
[mkdir] Created dir: E:\Groovy\projects\hello\lib
34
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\conf\spring
35
[mkdir] Created dir: E:\Groovy\projects\hello\grails-app\conf\hibernate
36
[propertyfile] Creating new property file: E:\Groovy\projects\hello\application.properties
37
[copy] Copying 2 files to E:\Groovy\projects\hello
38
[copy] Copied 1 empty directory to 1 empty directory under E:\Groovy\projects\hello
39
[copy] Copying 2 files to E:\Groovy\projects\hello\web-app\WEB-INF
40
[copy] Copying 5 files to E:\Groovy\projects\hello\web-app\WEB-INF\tld
41
[copy] Copying 28 files to E:\Groovy\projects\hello\web-app
42
[copy] Copying 18 files to E:\Groovy\projects\hello\grails-app
43
[copy] Copying 1 file to E:\Groovy\projects\hello
44
[copy] Copying 1 file to E:\Groovy\projects\hello
45
[copy] Copying 1 file to E:\Groovy\projects\hello
46
[copy] Copying 1 file to E:\Groovy\projects\hello
47
[propertyfile] Updating property file: E:\Groovy\projects\hello\application.properties
48
Created Grails Application at E:\Groovy\projects/hello

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

Hello是我們創建的第一個grails應用,grails自動為我們創建必要的目錄結構。
下節我們將基于這個目錄結構,進行第一個入門的HelloWorld應用開發。