YAT
YAT

Reputation: 466

Find Groovy Class in Source Folder

I have an Groovy class located in /src/groovy/ named testFilter. I want to find dynamicly filters, so i tried this:

def filterClass = grailsApplication.allClasses.find{it.name==className}

but that doesn't work for files in /src/groovy/

how can i find the class?

Upvotes: 2

Views: 611

Answers (2)

YAT
YAT

Reputation: 466

I've found a solution:

def classObject= Class.forName(CLASSNAME, false, Thread.currentThread().contextClassLoader).newInstance()

Upvotes: 0

Roman Romanovsky
Roman Romanovsky

Reputation: 578

Using grails you can only list domains classes, but you can use java for example : ClassLoader.

In your case code will be like:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
classLoader.getResource("src")

You can also find answer on your question here

Upvotes: 3

Related Questions