Update: According to Grails 1.3.6, you have access to the full domain from Gant scripts. From Grails 1.3.6 release notes :
Now you can run one or more Groovy scripts from the command line using the run-script command, for example
grails run - script [path to script -1] [path to script -2] ... [path to script -n]
This works around a problem in Gant scripts, where you cannot conveniently access application classes, since they are not available in the classpath when running scripts.
Hello everybody,
I am new to using Grails (in a real project) and I have a one-time script. I need to execute this by reading the file and then populating my database.
I wanted the script to run in the context of my grails application, so I used the create-script command. Now I understand that this is a "Gant" script. The reason for this was that I thought it would allow me to easily access the entire graffield domain, so that I could do something like this easily:
Car car = new Car(model: 'bar', brand: 'Ford')
car.save()
Here, Car is one of my domain classes, and I retrieved the string and Ford strings from my file.
The beginning of my script is as follows:
import com.foo.Car
grailsHome = Ant.project.properties."environment.GRAILS_HOME"
includeTargets << new File ( "${grailsHome}/scripts/Bootstrap.groovy" )
target(main: "a script for storing cars") {
depends(bootstrap, classpath)
Surprisingly, Groovy gives me java.lang.NoClassDefFoundError: com.foo.Carwhen I execute a script using the commandgrails LoadCars
Am I taking the wrong approach, or is there something simpler I'm doing wrong?
Any help is appreciated