通过 Apache Ant 来运行 Tomcat
生活随笔
收集整理的這篇文章主要介紹了
通过 Apache Ant 来运行 Tomcat
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Tomcat安裝目錄下的lib文件夾里的catalina-ant.jar 提供了下述的任務:
- InstallTask:安裝一個 web 應用程序。 類名字為: org.apache.catalina.ant.InstallTask
注意,我用tomcat 9試的時候,InstallTask已經被替換成DeployTask:
- ReloadTask:重新安裝一個 web 應用程序。類名字為: org.apache.catalina.ant.ReloadTask
- ListTask:列出所有的 web 應用程序。類名字為: Class Name: org.apache.catalina.ant.ListTask
- StartTask:啟動一個 web 應用程序。類名字為: org.apache.catalina.ant.StartTask
- StopTask:停止一個 web 應用程序。類名字為: org.apache.catalina.ant.StopTask
- ReloadTask:重新加載一個無需停止的 web 應用程序。類名字為:org.apache.catalina.ant.ReloadTask
build.properties的源代碼:
# Ant properties for building the spring appappserver.home=C:\\MyApp\\apache-tomcat-9.0.29appserver.lib=${appserver.home}/libdeploy.path=${appserver.home}/webappstomcat.manager.url=http://localhost:9032/manager tomcat.manager.username=jerry tomcat.manager.password=jerry@sapbuild.xml:
<?xml version="1.0" encoding="UTF-8"?> <project name="jerryjsp" basedir="." default="build"><property file="build.properties"/><property name="src.dir" value="src"/><property name="web.dir" value="WebContent"/><property name="build.dir" value="${web.dir}/WEB-INF/classes"/><property name="name" value="jerryjsp"/><path id="master-classpath"><fileset dir="${web.dir}/WEB-INF/lib"><include name="*.jar"/></fileset><fileset dir="C:/MyApp/apache-tomcat-9.0.29/lib"><include name="*.jar"/></fileset><pathelement path="${build.dir}"/></path><target name="build" description="Compile source tree java files"><mkdir dir="${build.dir}"/><javac destdir="${build.dir}" source="1.8" target="1.8"><src path="${src.dir}"/><classpath refid="master-classpath"/></javac></target><target name="clean" description="Clean output directories"><delete><fileset dir="${build.dir}"><include name="**/*.class"/></fileset><fileset dir="."><include name="*.war"/></fileset></delete></target><target name = "generate-javadoc"><javadoc packagenames="action.*" sourcepath="${src.dir}" destdir = "doc" version = "true" windowtitle = "Jerry Application"><doctitle><![CDATA[= Jerrt Application =]]></doctitle><bottom><![CDATA[Copyright ? 2020. JerryAll Rights Reserved.]]></bottom><group title = "action" packages = "action.*"/></javadoc><echo message = "java doc has been generated!" /></target><target name="build-war" depends="build"><war destfile="jerryjsp.war" webxml="${web.dir}/WEB-INF/web.xml"><fileset dir="${web.dir}"><include name="**/*.*"/></fileset></war></target><path id="catalina-ant-classpath"><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="deploywar" depends="build-war" description="Deploy application as a WAR file"><copy todir="${deploy.path}" preservelastmodified="true"><fileset dir="."><include name="*.war"/></fileset></copy></target> </project>執行命令行ant deploywar, 即可將JSP項目webcontent文件夾下的資源打成war包,然后復制到tomcat服務器的webapps文件夾內。
target deploywar依賴于build-war:
build-war依賴于build:
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的通过 Apache Ant 来运行 Tomcat的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第三方工具 Rufus 4.0 发布:默
- 下一篇: 使用ant触发Tomcat的reload