Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails console - Unable to find class?

Tags:

grails

groovy

I'm working through the "Grails in Action" book, and I'm stuck at that part that introduces the grails console. From my project directory, I typed "grails console" to open a console window, and the console even output information indicating it was compiling classes, but when I type this into the console:

new Quote(author:'Larry Wall',content:'There is more than one method to our madness.').save()

I get this error:

unable to resolve class Quote 
 at line: 1, column: 1

The Quote class exists in Quote.groovy in grails-app/domain/qotd/Quote.groovy, and I'm not able to run the above command.

What's going wrong here?

like image 503
Stefan Kendall Avatar asked Apr 16 '10 18:04

Stefan Kendall


2 Answers

Did you try importing the package that contains your domain class before trying to instantiate it?

import qotd.Quote
new Quote(author:'Larry Wall',content:'There is more than one method to our madness.').save()

to be sure you can also try specifying the full qualified name:

new qotd.Quote(author:'Larry Wall',content:'There is more than one method to our madness.').save()
like image 200
Jack Avatar answered Nov 04 '22 15:11

Jack


I'm going through the MEAP of Grails in Action second edition (2.1.1) and found that the solution is run:

grails clean
grails console

type the code in the groovy console again and run

like image 40
woodlumhoodlum Avatar answered Nov 04 '22 14:11

woodlumhoodlum