Question

I am trying to execute following code but I am getting null pointer exception.

 <property name="from" value="from"/>
            <property name="to" value="to"/>


            <taskdef name="groovy"
                classname="org.codehaus.groovy.ant.Groovy"
                classpath="G:\Tibco_Training\groovy-binary-1.8.5\groovy-all-1.6.5.jar" />

            <taskdef resource="net/sf/antcontrib/antlib.xml"/>
        <groovy>
                class MoveDir extends org.apache.tools.ant.Task {
                    //def from = 'from'
                    //def to = 'to'
                    public void execute() { 
                        new File(properties.from).eachFileMatch ~/.*/, { file ->
                        file.renameTo(new File(properties.to , file.getName()))
                        println "Moving file: $file.name from: " + from + "  to: " + to }
                    }
        }

                project.addTaskDefinition('movedir', MoveDir)
            </groovy>

            <movedir />

If I don't use ant properties in groovy then the code works fine, but when I use ant properties for specifying directories, then it give null pointer exception. Am I passing wrong values or wrong syntax is the cause.

No correct solution

OTHER TIPS

Wrong syntax, you have to use properties.'to' and properties.'from'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top