Desperately need help : java.lang.ClassNotFoundException: functional.*

232 views
Skip to first unread message

Owen Rubel

unread,
May 31, 2015, 12:58:02 AM5/31/15
to gra...@googlegroups.com
Am trying to scaffold functional tests for my plugin and nearly finished but have one FINAL bug.

I have to use '_GrailsRun' as a target to get 'config' properties, appCtx and grailsApp so I can read domain and services.

Upon running the script now for final write, it gives me an error like this:

Caused by: org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: functional.SectionFunctionalSpec
at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.<init>(DefaultGrailsApplication.java:146)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 249 more
Caused by: java.lang.ClassNotFoundException: functional.SectionFunctionalSpec
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:655)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:765)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:753)
at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.<init>(DefaultGrailsApplication.java:144)

Nw to put this into context, the template for the test is 'FunctionalSpec.groovy.template' with the name of each resource appended to the front.

In this case, you can see the error is for 'functional.SectionFunctionalSpec'... but this error is being thrown before anything is RUN!!! Nothing is being written yet.

How do I fix this and why is this occurring??

Owen Rubel

unread,
May 31, 2015, 11:16:25 AM5/31/15
to gra...@googlegroups.com
I have now removed all code functionality and have it down to the following code for the script

#########
 

templateDir = "$apiToolkitPluginDir/src/templates/tests"

testDir = "$basedir/grails-app/test/functional"


def grailsApplication

def ctx


target('scaffoldApiTest': 'Scaffolds API Objects based on Controllers') {

depends(cleanAll)

ant.delete(dir:"$basedir/target")

if (argsMap.https) {

runAppHttps()

}else {

runApp()

}

##############

... and I still get the error even with running '_GrailsClean' prior to '_GrailsRun' as targets.

It's NEVER creating this file but somewhere the app thinks it SHOULD be creating this file (prior to even running the script) , sticks it in target/classes but then looks for it under 'tests/functional'(???)

Owen Rubel

unread,
May 31, 2015, 12:47:02 PM5/31/15
to gra...@googlegroups.com
I also decoded the generated file being generated and it is NOTHING like my script!

################
import groovy.lang.*; 
import java.io.File; 
import java.lang.ref.SoftReference; 
import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory; 
import org.codehaus.groovy.reflection.ClassInfo; 
import org.codehaus.groovy.runtime.*; 
import org.codehaus.groovy.runtime.callsite.CallSite; 
import org.codehaus.groovy.runtime.callsite.CallSiteArray; 
import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling;   

public class SectionFunctionalSpec extends Script {   public SectionFunctionalSpec() { CallSite acallsite[] = $getCallSiteArray(); }

##############

I have no idea where this is being generated from, how or why!!


On Saturday, May 30, 2015 at 9:58:02 PM UTC-7, Owen Rubel wrote:

Owen Rubel

unread,
Jun 1, 2015, 11:01:35 AM6/1/15
to gra...@googlegroups.com
Ok so I tracked this down and now know the coe issue. This is an issue with the Spock functional test plugin. 

Now going to replace my functional tests or try to figure out a way to do this better with spock and without the plugin.


On Saturday, May 30, 2015 at 9:58:02 PM UTC-7, Owen Rubel wrote:

Owen Rubel

unread,
Jun 1, 2015, 11:08:31 AM6/1/15
to gra...@googlegroups.com
Since this is an issue with the Grails Spock Functional Plugin, I'm just going to switch to the Funky Spock plugin and give that a go.


On Saturday, May 30, 2015 at 9:58:02 PM UTC-7, Owen Rubel wrote:

Owen Rubel

unread,
Jun 1, 2015, 11:59:08 AM6/1/15
to gra...@googlegroups.com
Ok thats not it either. Apparently even removing the plugins and the plugin I was testing from the test app doesn't affect the error.

doing just a 'grails run-app' throws the error as well without running the script. And removing the script, remocving the plugins, removing the code doesn't see to change anything.

I have looked for this file but it doesn't exist as a line in the code or as a file anywhere on the system.

Doing a clean-all doesn't seem to fix this and it keeps failing with a :

###############
Caused by ClassNotFoundException: functional.SectionFunctionalSpec
->>  381 | findClass in java.net.URLClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    424 | loadClass in java.lang.ClassLoader
|    266 | run . . . in java.util.concurrent.FutureTask
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread


On Saturday, May 30, 2015 at 9:58:02 PM UTC-7, Owen Rubel wrote:

Aleh Bykhavets

unread,
Jun 1, 2015, 2:10:11 PM6/1/15
to gra...@googlegroups.com
Well, if after reverting to original project `grails run-app` fails you may try old trick.
In past it helped to deal with unexpected errors of unknown nature.

1) delete ./target/ folder in your project

2) delete cache at ~/.grails/<grails-version>/
(like it described here http://aftershox.com/2012/06/14/fixing-a-grails-plugin-cache-issue/ )

For example, for grails 2.3.1 it was ~/.grails/2.3.1/ on linux
or %USERPROFILE%\.grails\2.3.1\ on WIndows

But for grails 2.4+ it seems no longer required.


Then try to compile and run the project again.

Owen Rubel

unread,
Jun 3, 2015, 8:05:53 AM6/3/15
to gra...@googlegroups.com
Yeah did that. And the funny thing is the project still thinks there is a file by that name someplace. It's like there is a registry someplace with that name in it.

And I'm running 2.4.5 so that file is empty unfortunately. 

I was wondering if this might be stored in Maven or a registry someplace and be being pulled in at build/runtime??

Owen Rubel

unread,
Jun 3, 2015, 8:51:28 AM6/3/15
to gra...@googlegroups.com
I think this is a definite JIRA at this point.

So the underlying issue is that I ran createTemplate in a running app and it created a template which can be erased but there is a 'class registry' someplace so when classloader trys to call it, class can't be found.

clean-all does not get rid of this, restarting server, application does not get rid of this. deleting target does not get rid of this. This is happening in 2.4.5 so there is no .grails/project files. This is maven so there are no ivy files.

I am completely at a loss.

Owen Rubel

unread,
Jun 3, 2015, 10:34:46 AM6/3/15
to gra...@googlegroups.com
SOLVED! I'm an idiot (some one say 'no duh' please). I was creating the path for test/functional in 'grails-app' rather than at the 'root' of the application.

I couldn't see the class in test/functional because I created a DUPLICATE test/functional directory in grails-app.

I'm going to go flog myself now with a rabid duck!
Reply all
Reply to author
Forward
0 new messages