2009-11-02 6 views
1

자바 코드를 통해 ANT 빌드 스크립트의 SQL 작업을 실행 한 후에 디버깅 주석을 한 번 인쇄 한 적이없는 이유는 무엇입니까?자바 빌드 코드를 사용하여 작업을 실행하는 앤트 빌드 스크립트

빌드 scirpt에서 SQL을 실행하는 자바 클래스는

public class AntRunnerTest { 
    private Project project; 

    public void executeTask(String taskName) { 
     try { 
     project = new Project(); 
     project.init(); 
     project.setBasedir(new String(".")); 
     ProjectHelper helper = ProjectHelper.getProjectHelper(); 
     project.addReference("ant.projectHelper", helper); 
     helper.parse(project, new File("build-copy.xml")); 
     System.out.println("Before"); 
     project.executeTarget(taskName); 
     System.out.println("After"); 
     } catch(Exception ex) { 
      System.out.println(ex.getMessage()); 
     } 
    } 

    public static void main(String args[]) { 
     try { 
     AntRunnerTest newInst = new AntRunnerTest(); 
     newInst.executeTask("sql"); 
     } catch(Exception e) { 
     System.out.println(""+e); 
     } 
    } 
} 

내가 콘솔에 인쇄하기 "후"디버그 문자열을 볼 해달라고입니다. 이 문제는 java 코드를 사용하여 SQL 작업을 실행하려고 할 때만 나타났습니다.

개미 스크립트에는 다음과 같은 간단한 트랜잭션 태그가 있습니다.

<transaction> <![CDATA[ select now() ]]> </transaction> 

의견이 있으십니까? 사전에

감사합니다.

+0

는 일부 .txt 파일에 SQL 작업의 "출력"속성 값을 대체해야합니다. 그게 문제를 해결해야합니다. – Jay

+0

@Jay - 질문에 답한 경우 답을 게시하고 수락 할 수 있습니까? 답이없는 목록에는 질문이 표시되지 않습니까? –

+0

안녕하세요. 이 코드는 ant 파일 이름 build-copy.xml을 실행합니다. 파일이 이미 존재하거나 작성 중입니까? – Iso

답변

1

태그의 출력 속성을 추가하면 문제가 해결됩니다.

0
자바 코드를 사용하는 작업을 실행 Ant 빌드 스크립트

예 :

직접
  • 콘솔 바이트 어레이에 로그;
  • Ant 프로젝트 변수를 입력하십시오.
  • 개미 작업을 실행하십시오.
  • 스윙 컴포넌트에 출력 로그 추가 (javax.swing.JTextArea);

페이지의 소스 코드 : https://github.com/wellboyvg/workgear/blob/master/manager/src/manager/WorkGearManager.java

private boolean executeAntTask(String target) { 
boolean success = false; 
// use log output to the console 
DefaultLogger conlog = new DefaultLogger(); 
conlog.setErrorPrintStream(System.err); 
conlog.setOutputPrintStream(System.out); 
conlog.setMessageOutputLevel(Project.MSG_INFO); 
// use log output to the byte array 
DefaultLogger strlog = new DefaultLogger(); 
ByteArrayOutputStream errb = new ByteArrayOutputStream(); 
PrintStream errp = new PrintStream(errb); 
strlog.setErrorPrintStream(errp); 
ByteArrayOutputStream outb = new ByteArrayOutputStream(); 
PrintStream outp = new PrintStream(outb); 
strlog.setOutputPrintStream(outp); 
strlog.setMessageOutputLevel(Project.MSG_INFO); 
// prepare Ant 
Project project = new Project(); 
File buildfile = new File(buildname); 
project.setUserProperty("ant.file", buildfile.getAbsolutePath()); 
// add record log to the console 
project.addBuildListener(conlog); 
// add record log to the byte array 
project.addBuildListener(strlog); 
// 
try { 
    // fill the Ant project variables 
    for (Entry m : map.entrySet()) { 
    project.setUserProperty(m.getKey().toString(), m.getValue().toString()); 
    } 
    project.fireBuildStarted(); 
    project.init(); 
    ProjectHelper helper = ProjectHelper.getProjectHelper(); 
    project.addReference("ant.projectHelper", helper); 
    helper.parse(project, buildfile); 
    // execute the ant task 
    project.executeTarget(target); 
    project.fireBuildFinished(null); 
    success = true; 
} catch (BuildException buildException) { 
    project.fireBuildFinished(buildException); 
} 
// add output log to swing component (javax.swing.JTextArea) 
jtLog.append(new String(outb.toByteArray())); 
jtLog.append(new String(errb.toByteArray())); 
return success; 

}

관련 문제