AntBuilder@Eclipse

Eclipse plug-in中调用ant

AntBuilder.java

public class AntBuilder {

 private Map psMap=new HashMap();
 
 
 public void setProperty(String key,String value){
  psMap.put(key, value);
 }
 
 public boolean build(String buildFilePath,String baseDir) {
  return build(buildFilePath, baseDir,null);
 }

 public boolean build(String buildFilePath,String baseDir, String taskName) {
  File buildFile = new File(buildFilePath);  
  Project project = new Project();
  MessageConsole c=Logger.getLogger().getConsole();
  DefaultLogger consoleLogger = new DefaultLogger();
  IOConsoleOutputStream errOs=c.newOutputStream();
  errOs.setColor(ColorConstants.red);
  IOConsoleOutputStream outOs=c.newOutputStream();
  outOs.setColor(ColorConstants.blue);  
  consoleLogger.setErrorPrintStream(new PrintStream(errOs));
  consoleLogger.setOutputPrintStream(new PrintStream(outOs));

  consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
  project.addBuildListener(consoleLogger);
  for(Iterator iter=psMap.keySet().iterator();iter.hasNext();){
   String key=(String)iter.next();
   project.setProperty(key, (String)psMap.get(key)); 
  }
  project.setBasedir(baseDir);
  try {   
   project.fireBuildStarted();
   project.init();
   ProjectHelper helper = ProjectHelper.getProjectHelper();
   helper.parse(project, buildFile);
   
   if (taskName == null) {
    taskName = project.getDefaultTarget();
   }
   project.executeTarget(taskName);
   project.fireBuildFinished(null);
   return true;
  } catch (Exception e) {
   project.fireBuildFinished(e);
   return false;
  }
 }
}

builder.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="bibench_builder" default="build_war" basedir="."> 
 <property name="war.src" value="" />
 <property name="war.dest" value="bibench.war" />
 
 <target name="init">
  <delete file="${war.dest}"/>
 </target>
  
 <target name="build_war" depends="init">
  <war warfile="${war.dest}" webxml="${war.src}/WEB-INF/web.xml">
   <!--
   <lib dir="${war.src}/WEB-INF/lib"/>   
   <classes dir = "${war.src}/WEB-INF/classes"/>
   -->   
   <fileset dir="${war.src}">
    <include name="**/*"/>
    <exclude name="*.war"/>
    <exclude name=".*"/>
   </fileset>
  </war>
 </target>
</project>
Run

init:
   [delete] Deleting: D:/Eclipse3.2/runtime-EclipseApplication/for_build/bibench.war

build_war:
      [war] Building war: D:/Eclipse3.2/runtime-EclipseApplication/for_build/bibench.war
      [war] Warning: selected war files include a WEB-INF/web.xml which will be ignored (please use webxml attribute to war task)

BUILD SUCCESSFUL
Total time: 0 seconds

 

你可能感兴趣的:(eclipse,String,HashMap,iterator,Build,include)