简体   繁体   中英

grails / groovy NoClassDefFoundError when accessing a static variable

i think this is an easy one for you:

I have a Controller in which i want to access a static field within another class XY (groovy class, located in package src/groovy ...). But this gets an NoClassDefFoundError.

public class XY{ public static final String a = "something" }

in controller: XY.a causes error!!!

Other classes in the same package than Class XY dont cause problems.

what i am doing wrong?

It appears that you've oversimplified the example. NoClassDefFoundError is not the same as ClassNotFoundException . ClassNotFoundException happens when the class isn't there. NoClassDefFoundError happens when the class is there, but something that it references isn't. So it's a lot trickier to fix.

Does the XY package match the folder structure (ie if it's in the "com.foo" package, is it in src/groovy/com/foo)?

Try running 'grails clean' and running it again - it could be that there's some compiler confusion and re-compiling everything could fix it, or show the real problem.

I found out what the problem was:

The class XY compiled, but i tried to assign a "" to a (accidentallydeclared) static integer.

That was the reason why the whole class could not be initialized and the error occoured.

Are there any propertys to set the compiler to print warnings?

Thanks for your hints!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM