1.IDE搭建

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

 

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


搭建Grails开发环境

 

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


搭建Grails开发环境

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

2.Grails项目建立小试

切换到Grails视图



搭建Grails开发环境

 

新建Grails工程


搭建Grails开发环境

直接finish即可。

工具栏上这个图标


搭建Grails开发环境
 
可以输入grails命令


搭建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的配置,文件位置:


搭建Grails开发环境
 代码块如下:

 

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工作目录配置


搭建Grails开发环境
 配置工作目录位置,默认是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文件

配置说明:略

相关文章:

  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2021-08-14
  • 2022-12-23
  • 2021-08-20
  • 2021-08-06
  • 2021-11-09
  • 2021-08-19
  • 2021-07-05
相关资源
相似解决方案