Ant自定义任务,抛出StackOverflowError异常

Ant扩展任务,抛出StackOverflowError异常在继承Task做扩展任务时用到了父类的Project实例中的log方法,与此同时也在使用其它Output流实例向命令行输出信息,这时就会出现StackOverflowError的问题,需要注意。

java.lang.StackOverflowError问题重现场景

Java源代码,负责定义一个Ant任务,注意Project实例的应用

/**
 * 自定义Ant任务
 * @author WangYanCheng
 * @version 2011-10-20
 */
public class SimpleTask extends Task {
    private Project project;
    private List fileListArr = new ArrayList();
    @Override
    public void execute() throws BuildException {
        String message = project.getProperty("ant.project.name");
        project.log("Here is project " + message + ".", Project.MSG_ERR);
        project.log("My location is " + getLocation());
        for (Iterator iterator = fileListArr.iterator(); iterator.hasNext();) {
            //project.log(iterator.next().path, Project.MSG_INFO);
            System.out.println(iterator.next().path);
        }
    }
    public void setProject(Project proj) {
        this.project = proj;
    }
    public FileList createFileList() {
        FileList fileList = new FileList();
        fileListArr.add(fileList);
        return fileList;
    }
    /**
     * Nested Object
     * @author WangYanCheng
     * @version 2011-10-20
     */
    public class FileList {
        String path;
        public FileList(){}
        public String getPath() {
            return path;
        }
        public void setPath(String path) {
            this.path = path;
        }
    }
}

Ant源代码,描述了Ant任务

<?xml version="1.0" encoding="UTF-8"?>

  
  
	
   
   
	
    
    
		
     
     
	
    
    
	
    
    
		
     
     
		
     
     
			
      
       
        
        
      
     
     
	
    
    

   
   
  
  

异常信息

Buildfile: D:\work\workspace\mywork\leanant\SimpleTask.xml
jar:
      [jar] Building jar: D:\work\workspace\mywork\leanant\SimpleTask.jar
main:
Here is project SimpleTask.
My location is D:\work\workspace\mywork\leanant\SimpleTask.xml:9: 
ABC
ABC
ABCABCABCABCABCABCABCABCABCABC

BUILD FAILED
D:\work\workspace\mywork\leanant\SimpleTask.xml:9: java.lang.StackOverflowError

Total time: 922 milliseconds
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值