java调用ant的任务

,昨天看了下ant的开发手册,发现用java可以调用ant 的Task,呵呵,有意思,实验了一下,还真有用,下面是一个copy文件的类.  ant包含大量可用的Task,这下省事了.

 

package  blog.csdn.net.huangbin;
import  java.io.File;

import  org.apache.tools.ant.Project;
import  org.apache.tools.ant.Target;
import  org.apache.tools.ant.taskdefs.Copyfile;

public   class  CopyfileConverter  extends      TaskConverter {
    
private String src;
    
private String dest;
    
private boolean forceoverwrite = false;;
 
    
protected void execute() {
         
final class CopyfileEx extends Copyfile {
                
public CopyfileEx() {
                 project 
= new Project();
                project.init();
                taskType 
= "file";
                taskName 
= "copyfile";
                target 
= new Target();
            }
    
            }

        
        CopyfileEx task 
= new CopyfileEx();
        task.setSrc(
new java.io.File(this.getText(src)));
        task.setDest(
new File(this.getText(dest)));
        task.setForceoverwrite(forceoverwrite);
        task.execute();  
        
    }


    
public String getDest() {
        
return dest;
    }


    
public void setDest(String dest) {
        
this.dest = dest;
    }


    
public boolean isForceoverwrite() {
        
return forceoverwrite;
    }


    
public void setForceoverwrite(boolean forceoverwrite) {
        
this.forceoverwrite = forceoverwrite;
    }


    
public String getSrc() {
        
return src;
    }


    
public void setSrc(String src) {
        
this.src = src;
    }


}

你可能感兴趣的:(开发)