每次更改应用程序后都必须重新启动TomCat

时间:2013-01-10 22:47:08

标签: tomcat ant

我遇到了 TomCat 7 我对应用程序所做的任何更改的问题,我使用ant进行构建以查看这些更改,我必须不断重启服务器。只有当服务器关闭时,我才能构建部署,然后重新启动服务器,它就会起作用。

如果我没有重新启动服务器并且取消部署部署,那么应用程序我将收到 http:404错误

有人可以告诉我我需要做些什么来避免在每次改变时都重新启动它。

ANT构建文件:

<?xml version="1.0"?>


<project name="app" basedir="." default="usage">
    <property file="build.properties"/>

    <property name="src.dir" value="src"/>
    <property name="web.dir" value="war"/>
    <property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
    <property name="name" value="crimeTrack"/>

    <path id="master-classpath">
        <fileset dir="${web.dir}/WEB-INF/lib">
            <include name="*.jar"/>
        </fileset>

        <fileset dir="${appserver.lib}">
            <include name="servlet*.jar"/>

        </fileset>

        <pathelement path="${build.dir}"/>
    </path>

    <target name="usage">
        <echo message=""/>
        <echo message="${name} build file command list"/>
        <echo message="                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"/>       
        <echo message="                | Targets: ANT                                    |"/>                                       
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | build     --: Build the application             |"/>             
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | deploy    --: Deploy application as directory   |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | deploywar --: Deploy application as a WAR file  |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | install   --: Install application in Tomcat     |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | reload    --: Reload application in Tomcat      |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | start     --: Start Tomcat application          |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | stop      --: Stop Tomcat application           |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | list      --: List Tomcat applications          |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                ___________________________________________________"/>
        <echo message="                Targets: Database                                  "/>
        <echo message="                ___________________________________________________"/>
        <echo message="                | createTables --: Creates Database Tables        |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | emptyTables --: Empty Database Tables           |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | loadData  --: Loads data into Database Tables   |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                | showTables --: Lists the tables in Database     |"/>
        <echo message="                ---------------------------------------------------"/>
        <echo message="                ___________________________________________________"/>
        <echo message="                Targets: Junit                                     "/>
        <echo message="                ___________________________________________________"/>
        <echo message="                | tests --: Runs test on all objects using JUNIT  |"/> 
        <echo message=                 "${deploy.path}/${name} and ${build.dir}" /> 
        <echo message="                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"/>
    </target>

    <target name="build" description="Compile main source tree java files">
        <mkdir dir="${build.dir}"/>
        <javac destdir="${build.dir}" source="1.7" target="1.7" debug="true" includeantruntime="false" 
               deprecation="false" optimize="false" failonerror="true">
            <src path="${src.dir}"/>
            <classpath refid="master-classpath"/>
        </javac>
    </target>

    <target name="deploy" depends="build" description="Deploy application">
        <copy todir="${deploy.path}/${name}" preservelastmodified="true">
            <fileset dir="${web.dir}">
                <include name="**/*.*"/>
            </fileset>
        </copy>
    </target>

    <target name="deploywar" depends="build" description="Deploy application as a WAR file">
        <war destfile="${name}.war"
             webxml="${web.dir}/WEB-INF/web.xml">
            <fileset dir="${web.dir}">
                <include name="**/*.*"/>
            </fileset>
        </war>
        <copy todir="${deploy.path}" preservelastmodified="true">
            <fileset dir=".">
                <include name="*.war"/>
            </fileset>
        </copy>
    </target>

<!-- ============================================================== -->
<!--                           Tomcat tasks                         -->
<!-- ============================================================== -->

    <path id="catalina-ant-classpath">
        <!-- We need the Catalina jars for Tomcat -->
        <!--  * for other app servers - check the docs -->
        <fileset dir="${appserver.lib}">
            <include name="catalina-ant.jar"/>
        </fileset>
    </path>

    <taskdef name="install" classname="org.apache.catalina.ant.DeployTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="start" classname="org.apache.catalina.ant.StartTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>

    <target name="install" description="Install application on the Tomcat Server">
        <install url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"
                 path="/${name}"
                 war="${name}"/>
    </target>

    <target name="reload" description="Reload application on the Tomcat Server">
        <reload url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"
                 path="/${name}"/>
    </target>

    <target name="start" description="Start Tomcat application">
        <start url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"
                 path="/${name}"/>
    </target>

    <target name="stop" description="Stop Tomcat application">
        <stop url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"
                 path="/${name}"/>
    </target>

    <target name="list" description="List Tomcat applications on server">
        <list url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"/>
    </target>

<!-- End Tomcat tasks -->


<!-- ============================================================== -->
<!--                          TESTING JUNIT                         -->
<!-- ============================================================== -->

     <property name="test.dir" value="test"/>


    <path id="test-classpath">
                <fileset dir="${web.dir}/WEB-INF/lib">
                    <include name="*.jar"/>
                </fileset>
                <pathelement path="${build.dir}"/>
                <pathelement path="${test.dir}"/>
                <pathelement path="${web.dir}/WEB-INF/classes"/>
    </path>


        <target name="buildtests" description="Compile test tree java files">
            <mkdir dir="${build.dir}"/>
            <javac destdir="${build.dir}" source="1.7" target="1.7" debug="true"
                deprecation="false" optimize="false" failonerror="true">
                <src path="${test.dir}"/>
                <classpath refid="master-classpath"/>
            </javac>
        </target>

        <target name="tests" depends="build, buildtests" description="Run tests">
            <junit printsummary="on"
                fork="false"
                haltonfailure="false"
                failureproperty="tests.failed"
                showoutput="true">
                <classpath refid="test-classpath"/>
                <formatter type="brief" usefile="false"/>

                <batchtest>
                    <fileset dir="${build.dir}">
                        <include name="**/*Tests.*"/>
                        <exclude name="**/Jdbc*Tests.*"/>
                    </fileset>
                </batchtest>

            </junit>

            <fail if="tests.failed">
                tests.failed=${tests.failed}
                ***********************************************************
                ***********************************************************
                *************     Testing Found Errors!...    *************
                ***********************************************************
                ***********************************************************
            </fail>
        </target>

     <target name="dbTests" depends="build, buildtests,emptyTables,createTables,loadData" 
                description="Run db tests">
            <junit printsummary="on"
                fork="false"
                haltonfailure="false"
                failureproperty="tests.failed"
                showoutput="true">
                <classpath refid="test-classpath"/>
                <formatter type="brief" usefile="false"/>

                <batchtest>
                    <fileset dir="${build.dir}">
                        <include name="**/Jdbc*Tests.*"/>
                    </fileset>
                </batchtest>

            </junit>

            <fail if="tests.failed">
                tests.failed=${tests.failed}
                ***********************************************************
                ***********************************************************
                *************     Testing Found Errors!...    *************
                ***********************************************************
                ***********************************************************
            </fail>
        </target>

      <target name="clean" description="Clean output directories">
            <delete>                
                <fileset dir="${build.dir}">
                    <include name="**/*.class"/>
                </fileset>
            </delete>
        </target>

        <target name="undeploy" description="Un-Deploy application">
            <delete>
                <fileset dir="${deploy.path}/${name}">
                    <include name="**/*.*"/>
                </fileset>
            </delete>
        </target>



    <!-- ============================================================== -->
    <!--                          DataBase CrimeTrack                   -->
    <!-- ============================================================== -->

    <target name="createTables">
            <echo message="CREATE TABLES USING: ${db.driver} ${db.url}"/>
            <sql driver="${db.driver}"
                 url="${db.url}"
                 userid="${db.user}"
                 password="${db.pw}"
                 onerror="continue"
                 src="db/create_database_tables.sql">  
                <classpath refid="master-classpath"/>
            </sql> 
        </target>

        <target name="emptyTables">
            <echo message="EMPTY TABLES USING: ${db.driver} ${db.url}"/>
            <sql driver="${db.driver}"
                 url="${db.url}"
                 userid="${db.user}"
                 password="${db.pw}"
                 onerror="continue"
                 src="db/flush_data.sql">  
                <classpath refid="master-classpath"/>
            </sql> 
        </target>

        <target name="loadData">
            <echo message="LOAD DATA USING: ${db.driver} ${db.url}"/>
            <sql driver="${db.driver}"
                 url="${db.url}"
                 userid="${db.user}"
                 password="${db.pw}"
                 onerror="continue"
                 src="db/load_systems_tables.sql">  
                <classpath refid="master-classpath"/>
            </sql> 
        </target>

        <target name="showTables">
            <echo message="SHOW DATABASE TABLES USING: ${db.driver} ${db.url}"/>
            <sql driver="${db.driver}"
                 url="${db.url}"
                 userid="${db.user}"
                 password="${db.pw}"
                 onerror="continue"
                 print="true">  
                <classpath refid="master-classpath"/>

            SHOW TABLES;

            </sql> 
        </target>

         <target name="shutdownDb">
            <echo message="SHUT DOWN DATABASE USING: ${db.driver} ${db.url}"/>
            <sql driver="${db.driver}"
                 url="${db.url}"
                 userid="${db.user}"
                 password="${db.pw}"
                 onerror="continue">  
                <classpath refid="master-classpath"/>

            SHUTDOWN;

            </sql> 
        </target>   

</project>

1 个答案:

答案 0 :(得分:2)

您应该创建执行hotswap的ant任务。甚至有一个project可以帮助你做到这一点。或者,您可以使用jrebel,但它是商业产品。