Question

I'll still just a pup when it comes to using Groovy's and Grails' tools. I want to use groovyConsole to test some ideas. The code I want to try involves using Grails converters, json to be exact. I found a nice post that explains how to do this by adding classes to groovy-starter.conf rather than messing around with ClassPath. The last time I tried adding ClassPath all kinds of things went haywire on me!

So I like this idea of adding the code to groovy-starter.conf. I have located that file in $GROOVY_HOME/conf. Here's the article I speak of: DRY Groovy, How To Get Groovy To Import A Class Into a Script

The problem: I don't know exactly what to add to this. I want to add import grails.converters.json to my groovyConsole script. But being a newb I am not clear on what magic incantation I put in groovy-starter.conf!

I am thoroughly enjoying my newfound love for Groovy, but get a little frustrated when I can't get Google to cough up an answer to my questions. I think I have 75% of the answer but could use a little more guidance. I have JDK 1.6, Groovy 1.6.5 and grails-1.3.5 installed on this system. What magic words will fix my groory-starter.conf so I can access the Grails converters?

Was it helpful?

Solution

You can run grails console instead of groovyConsole - it does load all the application classes, has a database connection and everything.

OTOH, speaking of classes fro groovyConsole, you need to load a lot - $GRAILS_HOME/dist/grails-web-1.3.5.jar, and all of its dependencies like grails-core-1.3.5.jar and mode from $GRAILS_HOME/lib/.

OTHER TIPS

Solution to this is quite simple : you have to find out in which JARs are the classes json converters. But if I were you, I wouldn't go the hard way.

In Groovy scripts, I tend to prefer the Groovy Grapes way. it has the obvious disadvantage of duplicating JARs, as grails converters will be both in grails folder and in Groovy grapes repository one. However, it has the huge advantage and allowing you to use a precise version of your dependencies (making you test independant of your Grails installation, that may change over time).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top