搭建Grails开发环境

1.IDE搭建

使用SpringSource Tool Suite ,目前版本2.9.0,下载地址:http://www.springsource.org/downloads/sts,应该算是官方IDE吧。

 

安装或解压后打开(注:需要JVM的安装,配置好环境变量或更改STS.ini文件),选择 Install Extension


 

 如下图所示勾选三项,点install


安装完后重启,IDE环境就搭好了。

2.Grails项目建立小试

切换到Grails视图



 

新建Grails工程


直接finish即可。

工具栏上这个图标



 
可以输入grails命令



 输入如图命令回车(此处可按 Alt + / 提示)

console窗口中显示如下:

 

 

| Loading Grails 2.0.1

| Configuring classpath.

| Environment set to development.....

| Packaging Grails application.....

| Compiling 1 source files.....

| Running Grails application

| Server running. Browse to http://localhost:8080/grailsTest

 

 

访问http://localhost:8080/grailsTest 看到界面即可正常启动。

 

3.配置

3.1日志的配置

默认集成了log4j的配置,文件位置:



 代码块如下:

 

log4j = {
    // Example of changing the log pattern for the default console
    // appender:
    //
    //appenders {
    //    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
    //}

    error  'org.codehaus.groovy.grails.web.servlet',  //  controllers
           'org.codehaus.groovy.grails.web.pages', //  GSP
           'org.codehaus.groovy.grails.web.sitemesh', //  layouts
           'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
           'org.codehaus.groovy.grails.web.mapping', // URL mapping
           'org.codehaus.groovy.grails.commons', // core / classloading
           'org.codehaus.groovy.grails.plugins', // plugins
           'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
           'org.springframework',
           'org.hibernate',
           'net.sf.ehcache.hibernate'
}

 

 配置方法暂不讨论。

3.2工作目录配置



 配置工作目录位置,默认是USER_HOME/.grails:

grails.work.dir="e:\\grails"

 

grails 会把工程的插件放到这个目录中。

 

配置jar包存放位置,默认是USER_HOME/.grails/ivy-cache:

grails.dependency.cache.dir = "e:\\grails\\ivy-cache"

这里会把工程用到的jar放在里面,多个工程可同用一个目录,推荐配置一下这个,不然会把所有的jar放到C盘造成系统盘空间占用。

 

以上两个未找到配置到全局的方法,每生成一个工程都需要手工加。

 

3.3Maven配置

也在BuildConfig.groovy里

配置本地自建的maven仓库,照着下边被注释掉的mavenRepo写就可以了:

 

 

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve

    repositories {
        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()
        grailsHome()
        grailsCentral()
        mavenCentral()

        // uncomment these to enable remote dependency resolution from public Maven repositories
        //mavenCentral()

        //mavenRepo "http://snapshots.repository.codehaus.org"
        //mavenRepo "http://repository.codehaus.org"
        //mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"
    }
}

 

jar包下载后会被放到上一个配置的ivy-cache文件夹里。

这里可以做个本地maven库的配置,和自己的maven工程用同一个本地库。

mavenLocal("E:\\apache-maven\\repository")

这么配置以后jar包依然会被复制到ivy-cache里面。

 

这里可以加入工程需要的依赖,形式如下边被注释掉的mysql驱动。

 

 

dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

        // runtime 'mysql:mysql-connector-java:5.1.16'
    }

 这里要注意的是,如果是snapshot,则需要加上changing = true 的属性。

 

3.4数据库配置

DataSource.groovy文件

配置说明:略

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值