Grails compiler keeps running again and again, possibly because of syntax error
I got this problem several times: Sometimes when I command : grails run-app, the compiler just running again and again, even though I cha开发者_开发问答nge nothing after that. It looks like:
Running Grails application..
Server running. Browse to http://localhost:8080/LiningTest
[groovyc] Compiling 1 source file to E:\workspace\W1\LiningTest\target\classes
[groovyc] Compiling 2 source files to E:\workspace\W1\LiningTest\target\classe
s
[delete] Deleting directory C:\Documents and Settings\Long\.grails\1.3.6\proj
ects\LiningTest\tomcat
Running Grails application..
Server running. Browse to http://localhost:8080/LiningTest
[groovyc] Compiling 1 source file to E:\workspace\W1\LiningTest\target\classes
[groovyc] Compiling 2 source files to E:\workspace\W1\LiningTest\target\classe
s
[delete] Deleting directory C:\Documents and Settings\Long\.grails\1.3.6\proj
ects\LiningTest\tomcat
Running Grails application..
Server running. Browse to http://localhost:8080/LiningTest
[groovyc] Compiling 1 source file to E:\workspace\W1\LiningTest\target\classes
...
The compiler succeeded when "Server running", but then it automatically re-compile some files (I don't know which file), and run again, and then recompile again...
I have met this problem once when I have a syntax error
constraint {
number(min:0.50) // the right way is "min: 0..50"
}
The question is why this problem happened, and how I can find the cause of the problem. (I guess that I miss some comma/dot somewhere, but now it's hard to find, because of there's no error message!)
UPDATE: Now I see the problem is that I don't follow the folder structure rules when placing non-domain class in src/groovy.
The first thing to do is to run:
grails compile -verboseCompile
That will at least tell you what the problematic file is.
Apparently this can happen when
- The package name does not match the directory (under your source root) the file is in.
- The class name is different from the file name.
Have a look at this: http://www.pubbs.net/201007/grails/58100-grails-user-groovyc-causing-grails-to-loop-.html
And Peter Ledbrook mentioned it in his talk at the Groovy & Grails Exchange last week (at 29:20): http://skillsmatter.com/podcast/java-jee/talk-by-peter-ledbrook
I can confirm the strange behaviour.
I had two groovy classes in src/groovy
belonging to some package com.acme.foobar
.
Although for a while all went fine and Grails even compiled the classes and started the application (which was useable without exceptions) - at some point it did not stop to compile, start, delete all over again.
After I put the classes in src/groovy/com/acme/foobar
the behaviour stopped instantly.
The remark of using grails compile -verboseCompile
was useful. At least you can check if everything is allright as follows:
Call grails compile
twice:
If there is the same output of classes being compiled the second time you compile there will be a problem.
If grails splutters something like this:
Running script /Users/ug/Software/grails/scripts/Compile.groovy
Environment set to development
returning to prompt directly afterwards - the problem should be gone.
Ok, it's a strange behavior with Grails that a senior programmer just told it to me:
I put one of my non-domain class in src/groovy/warm.groovy. But the warm.groovy belongs to the package "liningtest". It seems that I must put "Warm" class inside "src/groovy/liningtest/warm.groovy" instead.
There's an implicit rule here:
The non-domain class put in src/groovy, must follow the folder structure that is alike to the package structure.
That's really a strange behavior, because it doesn't report any errors, just repeat compiling again and again... And for the most strange part, that works for me in the first time!
精彩评论