- Install Groovy
- Download groovy from http://groovy.codehaus.org/
- Follow installation steps from http://groovy.codehaus.org/Tutorial+1+-+Getting+started (OR) follow the following quick steps
- Unzip to a convenient directory that has no spaces
- set GROOVY_HOME env variable to the installed directory, also add %GROOVY_HOME%\bin; to env PATH
- Run groovysh from command promt; also try running groovyConsole from command prompt
- All set
- Install Grails
- Download grails from http://grails.org/Download
- Follow installation steps from http://grails.org/Installation
- All set
- Start a new Application
- C:\grails-apps>grails create-app appname (appname is optional, if not given, it will ask anyway)
- Check the directory appname and all sub-directories it creates under. The application is eclipse ready and ANT ready with .project and .classpath and build.xml files (it would have been more nicer if maven had been considered instead of ANT :) Hope to see MAVEN support added in coming releases).
- Import the project into eclipse.
- Setup new application for MySql
- Download ConnectorJ JDBC driver for Java from MySql Connector Download site
- Explode the zip and copy the jar to /lib directory under the newly created application
- Create databases (dev, test, prod) in MySql database. E.g. gspin_dev, gspin_test and gspin_prod
- Edit DataSource.groovy under /conf for MySql
- Create a domain class (.groovy)
E.g. User as follows - Run the application
- Check the gspin_dev and notice the table User created.
- Check the gspin_dev and notice the table User created
- Generate source
- C:\my-grails-app\gspin>grails generate-all
- Run the application and notice that you have got nice gui for all CRUD operations of your User domain object
- C:\my-grails-app\gspin>grails run-app
- Test the application
E.g.
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "root"
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://localhost/gspin_dev"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost/gspin_test"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost/gspin_prod"
}
}
}
class User {
String userId
String password
static constraints = {
userId()
password()
}
String toString() { this.userId }
}
E.g.
C:\my-grails-app\gspin>grails run-app
No comments:
Post a Comment