gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:58:50 25 4
gpt4 key购买 nike

我在使用 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>

最佳答案

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com