2008-01-03
Grails(Java笨狗)系列---Grails Getting Started(1)
- Downloading and Installing
- http://www.grails.org/Download下载最新版本
- 设置GRAILS_HOME环境变量
- Unix/Linux:GRAILS_HOME=/path/to/grails,PATH="$PATH:$GRAILS_HOME/bin"
- Windows:可以参考http://openmouse.javaeye.com/blog/152840的环境配置,主要设置GRAILS_HOME,和PATH. 设置完成,可以通过命令提示符中输入“Grails”检查你的配置是否正确
Welcome to Grails 1.0-RC1 - http://grails.org/ Licensed under Apache Standard License 2.0 Grails home is set to: /Developer/grails-dev/releases/grails-1.0-RC1 No script name specified. Use 'grails help' for more info如果提示类似于上面部分,说明你的配置正确,可以开始Grails之旅了。
- Creating an Application
- 这里我们假设你使用的是windows系统
- 打开命令行提示符,Grails提供了脚手架来创建项目,当然你的熟悉Grails的命令行
grails command name
上面的Grails的通用命令行 - 创建HelloWorld项目作为开始,使用命令行:
- 创建了项目,下面的步骤你将要导航到helloworld目录去完成,请注意这点
- 下面我们将在helloworld目录中为项目创建Controllers,对于使用过MVC的朋友,应该很清楚这点,被创建的Controllers的项目路径为:grails-app/controllers
grails create-controller hello
创建后的Controllers代码: grails run-app
通过上面的命令运行helloworld- 运行界面
grails create-app helloworld
cd helloworld
class HelloController {
def world = {
render "Hello World!"
}
} 
点击上面的HelloController将导航到显示Hello world!
- Getting Set-up in an IDE
- Convention over Configuration
- Grails使用的是“规约重于配置”,他的意思是,名字和位置来取代配置: 上面可以很好的看出
Grails的每个文件夹代表了实际的配置,这正是Grails的优点
| * grails-app - 顶层目录for Groovy sources o conf - 配置源文件. o controllers - Web controllers - The C in MVC. See Controllers o domain - 应用程序 domain. See GORM o i18n - 国际化支持 (i18n). See Internationalization (i18n) o services - 服务层. See Services(等同于SessionBean) o taglib - 标签库. See Tag Libraries o views - Groovy 服务器页面即GSP. See GSP * scripts - Gant 脚本. See Command Line Scripting * src - 源文件夹 o groovy - Groovy 源文件(除了controllers ,domain ,services之外的文件) o java - Java源文件 * test - 单元测试或者综合测试. See Testing |
- Running an Application
- 运行项目使用的命令行:
grails run-app
假如你使用不同的端口来运行:grails -Dserver.port=8090 run-app
- Testing an Application
- 测试:
grails test-app
- Deploying an Application
- 部署:
grails war
- Supported Java EE Containers
- 支持的服务器:
| * Tomcat 5.5 * Tomcat 6.0 * GlassFish v1 (Sun AS 9.0) * GlassFish v2 (Sun AS 9.1) * Sun App Server 8.2 * Websphere 6.1 * Websphere 5.1 * Resin 3.2 * Oracle AS * JBoss 4.2 * Jetty 6.1 * Jetty 5 * Weblogic 7/8/9/10 |
- 21:33
- 浏览 (643)
- 评论 (1)
- 分类: Groovy on Grails
- 发布在 JSF 圈子
- 相关推荐
评论
kwj
2008-01-25
我照着你的步骤做
可是到了这一步grails -Dserver.port=9090 run-app
在地址栏输入http://localhost:9090/helloworld
每次都有这样的错误:
Server running. Browse to http://localhost:9090/helloworld
2008-01-25 16:31:56.292:/helloworld:INFO: GSP servlet initialized
2008-01-25 16:31:58.886::WARN: Error for /helloworld/
java.lang.NoSuchMethodError: getContextPath
at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.createURLInter
nal(RegexUrlMapping.java:179)
at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.createURLInter
nal(RegexUrlMapping.java:241)
at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.createURL(Rege
xUrlMapping.java:225)
at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.createURL(Rege
xUrlMapping.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
95)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassH
elper.java:599)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:947)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHel
per.java:753)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.
java:741)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(Scrip
tBytecodeAdapter.java:167)
at org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib$_clos
ure4.doCall(ApplicationTagLib.groovy:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
95)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassH
elper.java:599)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:947)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
at groovy.lang.Closure.call(Closure.java:292)
我用的是Grails 1.0-RC4,不知是不是版本的问题
at org.codehaus.groovy.grails.web.pages.GroovyPage.captureTagOutput(Groo
vyPage.java:375)
2008-01-25 16:31:58.964:/helloworld:INFO: Initializing Spring FrameworkServlet
'grails-errorhandler'
我用的是
可是到了这一步grails -Dserver.port=9090 run-app
在地址栏输入http://localhost:9090/helloworld
每次都有这样的错误:
Server running. Browse to http://localhost:9090/helloworld
2008-01-25 16:31:56.292:/helloworld:INFO: GSP servlet initialized
2008-01-25 16:31:58.886::WARN: Error for /helloworld/
java.lang.NoSuchMethodError: getContextPath
at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.createURLInter
nal(RegexUrlMapping.java:179)
at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.createURLInter
nal(RegexUrlMapping.java:241)
at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.createURL(Rege
xUrlMapping.java:225)
at org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.createURL(Rege
xUrlMapping.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
95)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassH
elper.java:599)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:947)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHel
per.java:753)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.
java:741)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(Scrip
tBytecodeAdapter.java:167)
at org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib$_clos
ure4.doCall(ApplicationTagLib.groovy:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
95)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassH
elper.java:599)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:947)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
at groovy.lang.Closure.call(Closure.java:292)
我用的是Grails 1.0-RC4,不知是不是版本的问题
at org.codehaus.groovy.grails.web.pages.GroovyPage.captureTagOutput(Groo
vyPage.java:375)
2008-01-25 16:31:58.964:/helloworld:INFO: Initializing Spring FrameworkServlet
'grails-errorhandler'
我用的是
发表评论
- 浏览: 44027 次
- 性别:

- 来自: 郴州

- 详细资料
搜索本博客
我的相册
QQ截图未命名3
共 37 张
共 37 张
最近加入圈子
最新评论
-
JSF请求处理生命周期(一 ...
我觉得1、需要解释概念2、需要用实例说话3、概念说得不错
-- by lysmart_8 -
grails and tinymce
笨狗啊,你是一心放在在groovy&grails上了啊,不错,不错。学习了。
-- by rockjava -
Grails中文文档beta发布
感谢辛苦的劳动!
-- by vdgame -
那天好友对我说他哭了
好....
-- by qieren -
Grails中文文档beta发布
-- by zengsun






评论排行榜