由于项目的需求,需要在Eclipse中使用Java代码直接调用ant。调用的方法如下:
public class AntOperator {
public static void main(String[] args) {
// TODO Auto-generated method stub
AntOperator ao=new AntOperator();
ao.operateAnt("E:/antstudy/build.xml");
}
public void operateAnt(String path){
File buildfile=new File(path);
Project p=new Project();
p.init();
ProjectHelper helper=ProjectHelper.getProjectHelper();
helper.parse(p, buildfile);
p.executeTarget(p.getDefaultTarget());
}
}
但是在调用时,出现了如下异常:
Exception in thread "main" E:\antstudy\build.xml:70: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "F:\Program Files\Java\jre7"
at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(Co