sriram
sriram

Reputation: 9022

Adding methods to class and use them in other groovy code

I'm very new to Groovy. I have a class where I'm adding methods using metaClass. Here is the code I have for Parser.groovy:

PrivateClass.metaClass.convertDDTToMap { obj,fileLocation ->

}

where PrivateClass is a class coming from a jar. Now in other file named Hack.groovy I have the following code:

class Hack extends PrivateClass
{
//.. code
convertDDTToMap(param,param)
}

when I run Hack.groovy, I get the exception that the method convertDDTToMap is not there.

However Parser.groovy is in the same classpath and it gets compiled. But its not adding the method.

Where I'm making the mistake?

Upvotes: 0

Views: 35

Answers (1)

blackdrag
blackdrag

Reputation: 6508

Parser.groovy being compiled only is doing nothing, the code there needs to be called. For example using new Parser().run()

Upvotes: 3

Related Questions