문제

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.

올바른 솔루션이 없습니다

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top