Monday, 1 June 2009

Start, stop and debug Tomcat with Ant

This script shows how to start, stop and restart tomcat for the purpose of
development.

Enjoy!

<condition property="tomcat.started">
      <socket server="localhost" port="8180"/>
  </condition>

  <target name="tomcat-start" unless="tomcat.started">
    <java jar="${tomcat.dir}/bin/bootstrap.jar" fork="true">
      <jvmarg value="-Dcatalina.home=${tomcat.dir}"/>
    </java>
  </target>

  <target name="tomcat-stop" if="tomcat.started">
    <java jar="${tomcat.dir}/bin/bootstrap.jar" fork="true">
      <jvmarg value="-Dcatalina.home=${tomcat.dir}"/>
      <arg line="stop"/>
    </java>
  </target>

  <target name="tomcat-start-debug" description="start tomcat in debug mode" unless="tomcat.started">
    <java jar="${tomcat.dir}/bin/bootstrap.jar" fork="true">
      <jvmarg value="-Dcatalina.home=${tomcat.dir}"/>
      <jvmarg value="-Xdebug"/>
      <jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"/>
    </java>
  </target>

  <target name="redeploy" description="Stop, redeploy, start" >
    <antcall target="tomcat-stop"/>
    <sleep seconds="10"/>
    <antcall target="deploy_dev"/>
    <sleep seconds="10"/>
    <antcall target="tomcat-start"/>
  </target>

  <target name="redeploy-debug" description="Stop, redeploy, start with debugging turned on">
    <antcall target="tomcat-stop"/>
    <sleep seconds="10"/>
    <antcall target="deploy_dev"/>
    <sleep seconds="10"/>
    <antcall target="tomcat-start-debug"/>
  </target>

No comments: