2011-03-21 10 views
0

서버에서 maven 빌드를 수행하고 발생하는대로 콘솔 출력을 표시하는 웹 응용 프로그램을 만들고 싶습니다. 허드슨과 비슷한 것을 찾고 있습니다. 내가 여기 주어진 솔루션을 읽고webapp에 콘솔 출력을 표시합니다.

: Need to execute shell script from webapp and display console output in page

글쎄, 나는 스크립트를 실행할 수 및 전체 출력을 얻을,하지만 난 빌드가 일어나고로 UI를 업데이트 할 수 있습니다. 이것을 어떻게 할 수 있습니까?

JSF 및 Jboss Richfaces 구성 요소를 사용하여 이렇게 할 수 있습니까?

+1

의 형식을 별도로 사용하는 것이 좋습니다. 왜 허드슨을 사용할 수 없습니까? – Thilo

답변

1

예. Richfaces의 <a4j:poll>을 사용하면 주기적으로 서버에 대한 요청을 폴링 할 수 있습니다. 예를 들어,

보기 :

<a4j:region> 
     <h:form>   
      <a4j:poll id="poll" enabled="#{testBean.enablePolling}" reRender="consoleOutput,poll" /> 
     </h:form> 
</a4j:region> 

<h:form> 
    <a4j:jsFunction name="startBuild" action="#{testBean.startBuild}" /> 
    <a4j:commandButton value="Start Build" action="#{testBean.startPolling}" oncomplete="startBuild()" reRender="poll"/> 
    <hr/> 
    <h:outputText id="consoleOutput" value="#{testBean.consoleOuput}" escape="false"/> 
</h:form> 

MBean의 : 빌드 스크립트에 의해 출력

public class TestBean { 

    private boolean enablePolling; 
    private StringBuffer buildOutputSb = new StringBuffer(); 

    public TestBean() { 
    } 

     public boolean isEnablePolling() { 
     return enablePolling; 
    } 

    public void setEnablePolling(boolean enablePolling) { 
     this.enablePolling = enablePolling; 
    } 

    public void startPolling(){ 
     this.enablePolling = true; 
    } 

    public void startBuild(){ 

     this.buildOutputSb= new StringBuffer(); 

     //Stimulating the build process , which will output the log message to the buildOutputSb 
     for (int i=0 ; i <10 ; i++){ 
      buildOutputSb.append("Output").append(i).append("<br/>"); 
      try { 
       Thread.sleep(1000); 
      } catch (InterruptedException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
     this.enablePolling = false; 
    } 

} 

로그 메시지 문자열 버퍼 (buildOutputSb)에 추가하고, 우리가 사용하는 이 문자열 버퍼의 값을 UI에 표시하려면 <h:outputText id="consoleOutput">을 입력하십시오.

"Build Build"버튼을 누르면 속성이 true로 설정되어 <a4j:poll id="poll">을 활성화하고 주기적으로 서버 폴링을 시작합니다. 그동안 startBuild() (즉, 빌드 프로세스)이 실행됩니다. <a4j:poll id="poll" ><h:outputText id="consoleOutput">을 새로 고침하고 빌드 스크립트의 로그 메시지를 새로 고치는 것과 같이 각 폴링 라운드 후에 <h:outputText id="consoleOutput"> 번 (즉 업데이트)이됩니다.

<a4j:poll>은 풀링 라운드를 요청할 것이므로 session scope에 MBean을 등록하여 여러 번 인스턴스화되는 것을 방지합니다.

<a4j:poll>에 대한 자세한 정보 및 사용에 대한 우수 사례는 official demo을 참조하십시오. 예를 들어, <a4j:poll> 및 그 주변에 대해 <a4j:poll><a4j:region>

+0

감사합니다. – outvir

관련 문제