views:

386

answers:

2

I am maintaining a Grails application that I did not write(I have no experience with Groovy/Grails, actually :)) and it currently has a bug on one of the environments it's deployed on, but not others.

In order to debug this, I want to jump into the grails shell on the affected server, run the command that I suspect is error-prone, and see what results I get back to see where to go with my debugging next.

The application is put into a war file with the grails prod war command, scp'd to the server to be deployed on, and extracted with jar -xvf /path/to/war.

When I am in the grails shell, I am unable to access any of the classes defined in the domain.

This is what I try:

`

]$ ~/grails-1.0.4/bin/grails shell

Welcome to Grails 1.0.4 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /home/me/grails-1.0.4     

Base Directory: /var/home/me/skills_test/WEB-INF
Running script /home/me/grails-1.0.4/scripts/Shell.groovy
Environment set to development
     [copy] Copying 1 file to /home/me/.grails/1.0.4/projects/WEB-INF
     [copy] Copying 1 file to /home/me/.grails/1.0.4/projects/WEB-INF
Jun 11, 2009 2:35:19 PM java.util.prefs.FileSystemPreferences$7 run
WARNING: Prefs file removed in background /home/me/.java/.userPrefs/org/codehaus    /groovy/tools/shell/prefs.xml
Groovy Shell (1.5.6, JVM: 10.0-b22)
Type 'help' or '\h' for help.
        ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000> new User()
ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,     groovysh_evaluate: 2: unable to resolve class User 
 @ line 2, column 1.
1 error

        at Shell_groovy$_run_closure2.doCall (Shell_groovy:71)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure2.doCall (Shell_groovy)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure1.doCall (Shell_groovy:37)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure1.doCall (Shell_groovy)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at gant.Gant.dispatch (Gant.groovy:271)
        at gant.Gant.this$2$dispatch (Gant.groovy)
        at gant.Gant.invokeMethod (Gant.groovy)
        at gant.Gant.processTargets (Gant.groovy:436)
        at gant.Gant.processArgs (Gant.groovy:372)
groovy:000> import User
ERROR org.codehaus.groovy.tools.shell.CommandException: Invalid import definition:     'import User'; reason: startup failed, script1244745379552.groovy: 1: unable to resolve     class User
 @ line 1, column 1.
1 error

        at Shell_groovy$_run_closure2.doCall (Shell_groovy:71)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure2.doCall (Shell_groovy)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure1.doCall (Shell_groovy:37)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure1.doCall (Shell_groovy)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at gant.Gant.dispatch (Gant.groovy:271)
        at gant.Gant.this$2$dispatch (Gant.groovy)
        at gant.Gant.invokeMethod (Gant.groovy)
        at gant.Gant.processTargets (Gant.groovy:436)
        at gant.Gant.processArgs (Gant.groovy:372)
groovy:000>

`

as you can see, I can't access the "User" class(which lives in the domain directory - those are Grails' equivalent of 'models', right?) and can't import it either.

The examples of grails shell usage I've seen have all been able to access all classes in the application just fine without importing... what have I done wrong?

Is it because I'm running the grails shell against an extracted WAR file? How can I get around this?

+1  A: 

I'm not 100% sure, but I think that Groovy maintains the Java enforced-rule that you can't import classes with no package.

So try removing that import statement and see if you can work with the User object this way.

Robert Munteanu
+1  A: 

The issue was in fact that it was working from an extracted WAR file - I think it needs to have the source .java files present to work properly. I copied the original source files to the server I was having issues on, edited the configuration to point to the correct data sources, and was able to get into the shell fine.

Some reason you can't get into the shell in the directory with the extracted WAR file, but I will accept that for now because I've found a workaround.

ashgromnies