<target name=tomcat.restart depends="test.tomcat.stop, test.tomcat.start"/> <target name="test.tomcat.stop"> <property name="tomcat.start.cmd" value="C:\apache-tomcat-7.0.26\bin\shutdown.bat"/> <echo message="STOP WAS(tomcat)" /> <exec executable="cmd" failonerror="true"> <arg value="/c"/> <arg value="${tomcat.stop.cmd}"/> </exec> </target> <target name="test.tomcat.start"> <property name="tomcat.start.cmd" value="C:\apache-tomcat-7.0.26\bin\startup.bat"/> <echo message="START WAS(tomcat)" /> <exec executable="cmd" failonerror="true"> <arg value="/c"/> <arg value="${tomcat.start.cmd}"/> </exec> <!-- check whether WAS(tomcat) startup successfully through url call--> <property name="was.test.url" value="http://localhost:8080"/> <waitfor maxwait="3" maxwaitunit="minute" checkevery="500" timeoutproperty="was.fail"> <http url="${was.test.url}"/> </waitfor> <fail><condition> <isset property="was.fail"/></condition></fail> </target>
spawn=”false”를 설정한 경우, (ant 스크립트가 구동되는 빌드서버가 windows이면) cmd창이 뜬다. 물론 <test.tomcat.stop>이 실행될 때, 창이 저절로 닫히지만, 어떤 특이한 경우에는 안닫히는 경우가 있다.
cmd창이 뜨는 것을 막기위해 exec 타스크에 spawn=”true”를 세팅하는 것을 고려해 볼 수 있는데, 이 경우 cmd창 문제는 해결되지만, failonerror=”true”옵션이 안먹히는 것을 비롯하여 exec의 결과를 확인할 수 있는 방법이 없어지며,ant 스크립트 수행 종료가 되지 않는다.(수행종료를 위해 timeout을 세팅할 수 있긴 하다.)
위 예에서 tomcat start 수행 성공 여부야 ${test.url}로 확인한다 치지만, tomcat stop 수행 실패는 알 수가 없다.
위 예에서 tomcat start 수행 성공 여부야 ${test.url}로 확인한다 치지만, tomcat stop 수행 실패는 알 수가 없다.
cmd창을 닫아볼려고, tomcat을 java class로 start, stop해 볼려고 했는데 대상 서버의 여러가지 문제가 발생했고(jvm 버전,실행권한), 끝내 tomcat 구동/중지기능을 windows서비스로 등록하였다.