Disposable graph columns to populate the database

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) // code dealing with the file with cars follows

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

+5
source share
4

grails run- script Gant script ( Jared) grails 1.3. 5. - , , ).

script, , "scripts" grails, groovy script :

grails run-script script-path/boostrapMyDataIntoApp.groovy
+2

, , , , , , .

, , , , , - .

+6

, script, GORM grails script. . . , script grails 1.3, script .

+1

, , , GANT 8 ^)

, TDD , ? db-stuff? , ( JUnit) dbUnit, Java Groovy.

* db-stuff < 0.3.0 > - db / . // .


BootStrap - , / . .

, :

class BootStrap {

    def init = { servletContext ->
        if (GrailsUtil.environment.equals( GrailsApplication.ENV_DEVELOPMENT )) {
            log.info( "Loading sample data for 2010 models..." );            

            new Car( manufacturer: new Manufacturer( name: "Toyota" ), model: "Prius" )
            new Car( manufacturer: new Manufacturer( name: "GM" ), model: "Volt" )
//...
+1

All Articles