Recently, I was investigating how to integrate CFMX and Java Servlets.

I found that I needed to cycle the CFMX application after each change to my Java classes. In order to make this process less onerous I developed the following ant build file. You’ll notice that the CFMX log files are deleted. This was done so that I didn’t have to wade through large files in order to find the messages related to whatever change I was making at the time. You might also notice that I’ve added a four second delay before each delete task. This delay gives the operating system time to write its buffers to disk and close the files after the service has been stopped.</p>

<project name="dispatcher" default="" basedir=".">

    <property name="cfmx.home"            value="c:/CFusionMX" />
    <property name="cfmx.runtime-log.dir" value="${cfmx.home}/runtime/logs" />
    <property name="cfmx.log.dir"         value="${cfmx.home}/logs" />
    <property name="cfmx.service"         value="ColdFusion MX Application Server" />

    <property name="apache.home"          value="D:/Program Files/Apache Group/Apache" />
    <property name="apache.service"       value="Apache" />
    <property name="apache.log.dir"       value="${apache.home}/logs" />

    <property name="login.url"            value="http://localhost/login.cfm?userid=david&password=password" />
    <property name="temp.dir"             value="${user.home}/Temp" />

    <target name="restart_cfmx" description="Deploys Dispatcher servlet to CFMX.">
        <exec executable="c:/WINNT/system32/net.exe">
            <arg value="stop" />
            <arg value="${cfmx.service}" />
          </exec>

        <echo>Sleeping for 4 seconds.</echo>
        <sleep seconds="4"/>

        <!-- delete CFMX log files -->
        <delete>
            <fileset dir="${cfmx.log.dir}" includes="*.log"/>
            <fileset dir="${cfmx.runtime-log.dir}" includes="*.log"/>
        </delete>

        <exec executable="c:/WINNT/system32/net.exe">
            <arg value="start" />
            <arg value="${cfmx.service}" />
        </exec>

        <echo>Sleeping for 4 seconds.</echo>
        <sleep seconds="4"/>

        <get src="${login.url}" dest="${temp.dir}" />
        <echo>Done!</echo>
    </target>

    <target name="restart_apache" description="Deploys Dispatcher servlet to CFMX.">
        <exec executable="c:/WINNT/system32/net.exe">
            <arg value="stop" />
            <arg value="${cfmx.service}" />
        </exec>

        <echo>Sleeping for 4 seconds.</echo>
        <sleep seconds="4"/>

        <!-- delete CFMX log files -->
        <delete>
            <fileset dir="${cfmx.log.dir}" includes="*.log"/>
            <fileset dir="${cfmx.runtime-log.dir}" includes="*.log"/>
        </delete>

        <exec executable="c:/WINNT/system32/net.exe">
            <arg value="stop" />
            <arg value="${apache.service}" />
        </exec>

        <echo>Sleeping for 4 seconds.</echo>
        <sleep seconds="4"/>

        <!-- delete Apache log files -->
        <delete>
            <fileset dir="${apache.log.dir}" includes="*.log"/>
        </delete>

        <exec executable="c:/WINNT/system32/net.exe">
            <arg value="start" />
            <arg value="${apache.service}" />
        </exec>

        <exec executable="c:/WINNT/system32/net.exe">
            <arg value="start" />
            <arg value="${cfmx.service}" />
        </exec>

        <echo>Sleeping for 4 seconds.</echo>
        <sleep seconds="4"/>

        <get src="${login.url}" dest="${temp.dir}" />
        <echo>Done!</echo>
        </target>

</project>