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

标签 tomcat ant

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

如果我不重新启动服务器,并且取消部署部署应用程序,我将收到http :404 错误。 p>

有人可以告诉我我需要做什么才能避免每次更改时都重新启动吗?

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>

最佳答案

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

关于tomcat - 每次更改应用程序后都必须重新启动 TomCat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14268688/

相关文章:

tomcat - 阻止 URL 中的 IP 以响应服务器

java - MySQL DB 服务器在保存时间戳列时使用系统时区

java - java jar 的 Macrodef 中的可选 sysproperty

机器人/位图.h : No such file or directory (after updating Android SDK tools to revision 14)

ant - 找不到 : com/jcraft/jsch/UserInfo

java - 如何让 ant4eclispe 构建一个包含所有依赖项的项目?

java - 如何更改错误无法调用 Tomcat 管理器 : Server returned HTTP response code: 403

java - 使用 Spring MVC、Tomcat 应用程序为静态资源启用浏览器缓存

apache - Tomcat 在第一次请求时与 jsvc 结合失败

ant - 如何克服 Ant 中文件名的大小写敏感问题