Grails console - Unable to find class?

10,621

Solution 1

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

Solution 2

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

Share:
10,621
Stefan Kendall
Author by

Stefan Kendall

Updated on July 10, 2022

Comments

  • Stefan Kendall
    Stefan Kendall almost 2 years

    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?

  • Stefan Kendall
    Stefan Kendall about 14 years
    Odd. Since the book didn't mention it, I assumed I was getting auto-import magic, or something.
  • oligofren
    oligofren about 13 years
    This is a problem with Grails In Action. At the time of writing this worked, but it changed with later grails versions ...
  • Salman Paracha
    Salman Paracha over 12 years
    I am experiencing the same problem, and despite doing what this answer suggests, I am still not successful. Any other ideas?