0

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?

Kara
  • 6,115
  • 16
  • 50
  • 57
Rich Sadowsky
  • 966
  • 1
  • 12
  • 22

2 Answers2

2

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/.

Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91
  • thanks. I hadn't even thought to try grails console. I guess I kind of thought it was the same thing! I will give this a try. – Rich Sadowsky Feb 23 '11 at 20:51
1

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).

Riduidel
  • 22,052
  • 14
  • 85
  • 185
  • Ah, I like this answer. I haven't really started using Grapes, but this sounds like this might be a good time to start. I don't use groovyConsole a lot, but I often fire it up while working on some bigger piece of code in IntelliJ to help me test my understanding of some Groovy syntax. ps. I tried to vote this as a good answer, but the site told me I didn't have enough reputation points yet. Apparently 30 years of programming isn't enough!!! – Rich Sadowsky Feb 23 '11 at 20:52
  • You could have accepted this as the correct answer to your problem, although I do think @Victor_Sergienko one is far more accurately related to your precise problem. – Riduidel Feb 24 '11 at 19:39