Grails(12)Prepare My Working Environment
Grails(12)PrepareMyWorkingEnvironment
PartOneObtainingEnvironmentTools
1.Preparemygithubaccount
2.SettingupMySQL
3.Grailswitholdversion1.3.7
Downloadtheoldversion1.3.7fromherehttp://grails.org/download
Unzipthefileandputinmyworkingdirectoryandlnalinkto/opt
Sorightnow,Ihavemygrailson/opt/grails-1.3.7
4.IalreadyinstalledtheSTS.
5.SetUpGrails
Followthisdocumentandsetupgrails
http://grails.org/doc/1.3.7/guide/2.%20Getting%20Started.html#2.1DownloadingandInstalling
>cd~/
>vi.profile
exportGRAILS_HOME=/opt/grails-1.3.7
exportPATH=/opt/grails-1.3.7/bin:$PATH
>..profile
ButwhenItypecommandgrails,Igeterrormessage
ErrorMessages:
ErroropeningzipfileorJARmanifestmissing:/opt/grails-1.3.7/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-1.0.6.jar
ErroroccurredduringinitializationofVM
agentlibraryfailedtoinit:instrument
Solution:
Maybethatisbecausemylatest2.1.0version.Iwilluninstallmylatestversionfirst.
>grailshelp
AndItypethecommand
>grails
Igottherightversionof1.3.7.
6.STSPlug-inAcquisition
Dashboard---->GrailsSupportandGroovyEclipse
7.STSGrailsPlug-inSetUp
References---->Groovy--->Grails---->Add1.3.7
Andthegroovycompileto1.7
PartTwoSettingUpMyWorkspace
1.Getalltheprojectfromgithub.
2.SetUpprojectConfiguration
3.ImportingExistingProjects
Ifthereisnot.projectthereinthatprojectdirectory.JustcreateanewnormalprojectonSTS.Donotuseimportproject.
>grailsclean
>grailsupgrade
AndrefreshthedependencyinSTS.
Finally,Isuccessfullyimportedalltheprojects.
ButmygitcannotfetchfromremotefromSTS,Iwillfixthatlater.
4.CreatingaUserfortheDatabase
Enterthemysqlonmylocalmachine
>mysql-uroot-p
mysql>createdatabasesample;
mysql>grantallonsample.*to"username"@"localhost"identifiedby"111111";
mysql>exit;
Thenlogintothemysqlwiththenewlycreateduserandpassword.
>mysql-uusername-p111111
5.UpgradingCurrentGrailsApplication
upgradeallthegrailsproject
6.RefreshDependencies
7.Debugging
InSTS,chooseDebugConfigurations--->CreatenewinGrailsandgrailscommand
--->-DServer.port=9090run-app
9.CreatingVirtualHost
>vi/etc/hosts
Modifyandfindthevirtualmachine.
Part3SomeTipsfromDocuments
2.6ConventionoverConfiguration
2.7RunninganApplication
>grails-Dserver.port=9090run-app
3.Configuration
3.1.3GORM
3.7.2DependencyRepositories
repositories{
mavenCentral()
ebr()
mavenRepo"http://repository.some.org"
}
LocalDirectory
repositories{
flatDirname:'myRepo',dirs:'/path/to/repo'
}
LocalMavenrepository~/.m2/repository
repositories{
mavenLocal()
}
4.TheCommandLine
5.ObjectRelationalMapping(GORM)
Part4GroovyReview
Opengroovyconsole
>groovyconsole
println"hello,Carl"
type<CTRL+R>
x=1
printlnx
x=newjava.util.Date()
printlnx
Itseemsthatwedonothavetypeforvariables.Sowecanassigndifferentvaluetothem.
ListsandMaps
Built-insupportfor2datatypes,listfororderedcollectionsofdata.
myList=[12,-1,33,0]
printlnmyList[1]
printlnmyList.size()
Mapisunorderedcollections
scores=['carl':168,'kiko':199]
printlnscores
printlnscores['carl']//168
printlnscores.kiko//199
Andwecaneasilyaddingoneproducttomapscores
scores['peter']=1000
printlnscores.peter
Emptythemap
emptyMap=[:]
emptyList=[]
Closures
square={it*it}
printlnsquare(9)//81
newList=[1,3,4,5].collect(square)
printlnnewList//[1,9,16,25]
Bydefaultclosurestake1parametercalled"it".Aclosureformap.
printMap={key,value->printlnkey+"="+value}
['carl':168,'kiko':199].each(printMap)
//carl=168
//kiko=199
Part5ErrorMessages
IhaderrormessagewhenItriedtofetchthesourcecodesfromgithubinSTS.
ErrorMessages:
https://github.com/name/project:https://github.com/name/project/info/refs?service=git-upload-packnotfound
Solution:
ThenIgototheSTSandgitclonetheprojectinGitRepositoryExploring,thatworks.
References:
http://grails.org/doc/1.3.7/guide/2.%20Getting%20Started.html#2.1DownloadingandInstalling
http://grails.org/doc/1.3.7/
http://grails.org/doc/1.3.7/guide/3.%20Configuration.html
http://groovy.codehaus.org/Getting+Started+Guide