`
Javabengou
  • 浏览: 172712 次
  • 性别: Icon_minigender_1
  • 来自: 郴州
社区版块
存档分类
最新评论

Grails(Java笨狗)系列---Grails Getting Started(1)

阅读更多
  • Downloading and Installing
  1. http://www.grails.org/Download下载最新版本
  2. 设置GRAILS_HOME环境变量
  3. Unix/Linux:GRAILS_HOME=/path/to/grails,PATH="$PATH:$GRAILS_HOME/bin"
  4. Windows:可以参考http://openmouse.iteye.com/blog/152840的环境配置,主要设置GRAILS_HOME,和PATH.
  5. 设置完成,可以通过命令提示符中输入“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
  1. 这里我们假设你使用的是windows系统
  2. 打开命令行提示符,Grails提供了脚手架来创建项目,当然你的熟悉Grails的命令行
    grails command name
    上面的Grails的通用命令行
  3. 创建HelloWorld项目作为开始,使用命令行:
  4. grails create-app helloworld
  5. 创建了项目,下面的步骤你将要导航到helloworld目录去完成,请注意这点
  6. cd helloworld
  7. 下面我们将在helloworld目录中为项目创建Controllers,对于使用过MVC的朋友,应该很清楚这点,被创建的Controllers的项目路径为:grails-app/controllers
    grails create-controller hello  
  8. 创建后的Controllers代码:
    class HelloController {
    	def world = {
    		render "Hello World!"
    	}
    }                           
  9. grails run-app
    通过上面的命令运行helloworld
  10. 运行界面


点击上面的HelloController将导航到显示Hello world!
  • Getting Set-up in an IDE
关于IDE的介绍可以去Grails查看,这里不再讲述。
  • 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
  1. 运行项目使用的命令行:
    grails run-app
    假如你使用不同的端口来运行:
    grails -Dserver.port=8090 run-app
  • Testing an Application
  1. 测试:
    grails test-app
  • Deploying an Application
  1. 部署:
  2. 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

 

0
0
分享到:
评论
1 楼 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'

我用的是

相关推荐

    Getting-Started-with-Grails-Chinese.rar_Getting Started_grails

    《Getting Started with Grails》是一本面向初学者的指南,主要介绍了Grails这一现代Web开发框架的使用。Grails是一个基于Groovy语言的开源框架,它简化了Java平台上的Web应用开发,提供了丰富的功能和高效的生产力...

    grails-getting-started

    1. **安装Java**:Grails是基于Java的,因此首先需要在计算机上安装JDK。 2. **安装Groovy**:作为Grails的基础语言,Groovy的安装也是必不可少的。 3. **安装Grails**:可以通过Maven或直接下载二进制文件的方式...

    Getting-Started-with-Grails-Chinese

    这本书《Getting Started with Grails 中文版》是为初学者准备的一份指南,帮助他们快速理解 Grails 框架的基本概念和工作流程。书中可能涵盖了以下内容: 1. **安装与配置**:介绍如何在各种操作系统上设置 Grails...

    Grails入门指南书籍和源码----下载不扣分,回帖加1分,欢迎下载,童叟无欺

    getting started with grails chinese Grails入门指南书籍和源码----下载不扣分,回帖加1分,欢迎下载,童叟无欺 getting started with grails chinese Grails入门指南书籍和源码----下载不扣分,回帖加1分,欢迎...

    getting started with grails 中文版

    非常好的grails教材, 建议grails程序员参考

    Grails Getting Started-II.pdf

    综上所述,Grails Getting Started-II.pdf这份文档很可能涵盖了从环境搭建、应用开发到部署的一系列详细指导,对于初学者来说是一份非常有价值的参考资料。通过学习这些内容,开发者可以快速掌握Grails框架的基本...

    Grails Getting Started II 中文版

    《Grails Getting Started II 中文版》是一本针对Grails框架初学者的指南,旨在帮助读者快速掌握Grails开发的基本技能和核心概念。Grails是一个基于Groovy语言的开源Web应用框架,它提供了丰富的功能和工具,使得...

    Getting Started with Grails

    Grails是一个全栈式的Web应用开发框架,基于一系列成熟且广受好评的开源技术构建,如Spring、Hibernate、Ant、JUnit等。它充分利用了Groovy动态编程语言的优势,并遵循约定优于配置(Convention over Configuration...

    Groovy and Grails Recipes(清晰PDF)

    Getting Started with Grails** - **介绍**: 介绍了如何开始使用Grails框架。 - **核心知识点**: - Grails安装过程 - 创建第一个Grails应用 - Grails项目的基本结构 **11. The Web Layer** - **介绍**: 探讨...

    Grails开发指南

    《Getting-Started-with-Grails-Chinese.pdf》这本书的中文版,将引导读者逐步了解Grails的安装配置、基础概念、核心特性,以及如何快速构建第一个应用。首先,你会学习如何在不同的操作系统上安装Grails,包括Java...

    Flex.on.Java.rar

    Part 1: Getting started 1. Some Flex with your Java 2. Beginning with Java 3. Getting Rich with Flex 4. Connecting to Web Services Part 2: Strengthening the backend 5. BlazeDS remoting and ...

    Programming Groovy

    - **Jason Rudolph (《Getting Started with Grails》作者)**:认为本书是快速掌握Groovy元编程的最佳资源之一。 - **Scott Davis (aboutGroovy.com 编辑)**:强调本书不仅仅停留在语法层面,而是深入探讨了Groovy...

    IntelliJ IDEA 2017.2 Help.PDF

    新用户可以通过“Getting Started with Java”教程快速入门,学习如何创建和运行Java应用程序。另外,该文档还包含了针对多种技术栈的流行教程,例如Java EE、Android开发、Grails、Groovy、Gradle和Scala等,帮助...

    ehcache官方教程

    #### 二、开始使用(Getting Started) 1. **安装与配置**:Ehcache 的安装非常简单,只需将 ehcache.jar 添加到项目的 classpath 中即可。此外,可以通过 ehcache.xml 配置文件来定制缓存策略。 2. **快速上手**:...

    EhcacheUserGuide

    #### 二、入门指南(Getting Started) 对于初学者来说,Ehcache提供了一个易于上手的入门指南,帮助新用户快速了解如何配置和使用Ehcache。这包括了基本的安装步骤、环境配置、简单的代码示例等,让开发者能够快速...

    Spring.Boot.in.Action.2015.12.pdf

    1.2 Getting started with Spring boot 8 Installing the spring boot cli 8 Initializing a spring boot project with Spring Initializr 12 3 Summary 22 Developing your first Spring Boot application 23 2.1 ...

Global site tag (gtag.js) - Google Analytics