当前位置:K88软件开发文章中心编程工具Apache Ant → 文章内容

Ant 部署应用

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-24 10:03:07

由 ?﹏???ζ???﹏﹏? 创建,路飞 最后一次修改 2016-08-12 Ant 部署应用在之前的章节中,我们已经学会了如何去打包一个应用程序以及怎样将其部署到一个文件夹中。在这个章节中,我们将要直接将 web 应用程序部署到一个应用服务器的部署文件夹中。随后,我们将添加一些 Ant 目标来启动和停止服务。让我们继续 Hello World fax web 应用程序。 这一章节是对之前的章节的一个延续,所有新的组件会用粗体突出显示。build.properties# Ant properties for building the springappappserver.home=c:\\install\\apache-tomcat-7.0.19# for Tomcat 5 use $appserver.home}/server/lib# for Tomcat 6 use $appserver.home}/libappserver.lib=${appserver.home}/libdeploy.path=${appserver.home}/webappstomcat.manager.url=http://www.tutorialspoint.com:8080/managertomcat.manager.username=tutorialspointtomcat.manager.password=secretbuild.xml<?xml version="1.0"?><project name="fax" basedir="." default="usage"> <property file="build.properties"/> <property name="src.dir" value="src"/> <property name="web.dir" value="war"/> <property name="javadoc.dir" value="doc"/> <property name="build.dir" value="${web.dir}/WEB-INF/classes"/> <property name="name" value="fax"/> <path id="master-classpath"> <fileset dir="${web.dir}/WEB-INF/lib"> <include name="*.jar"/> </fileset> <pathelement path="${build.dir}"/> </path> <target name="javadoc"> <javadoc packagenames="faxapp.*" sourcepath="${src.dir}" destdir="doc" version="true" windowtitle="Fax Application"> <doctitle><![CDATA[<h1>= Fax Application = </h1>]]></doctitle> <bottom><![CDATA[Copyright © 2011. All Rights Reserved.]]></bottom> <group title="util packages" packages="faxapp.util.*"/> <group title="web packages" packages="faxapp.web.*"/> <group title="data packages" packages="faxapp.entity.*:faxapp.dao.*"/> </javadoc> </target> <target name="usage"> <echo message=""/> <echo message="${name} build file"/> <echo message="-----------------------------------"/> <echo message=""/> <echo message="Available targets are:"/> <echo message=""/> <echo message="deploy --> Deploy application as directory"/> <echo message="deploywar --> Deploy application as a WAR file"/> <echo message=""/> </target> <target name="build" description="Compile main source tree java files"> <mkdir dir="${build.dir}"/> <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" 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> <target name="clean" description="Clean output directories"> <delete> <fileset dir="${build.dir}"> <include name="**/*.class"/> </fileset> </delete> </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.InstallTask"> <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="reload" description="Reload application in Tomcat"> <reload url="${tomcat.manager.url}"username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}"/></target></project>在这个例子中,我们已经使用 Tomcat 作为我们应用的服务器。 首先,在构建属性文件中,我们已经定义了一些附加属性。appserver.home 指向 Tomcat 服务器的安装路径。appserver.lib 指向 Tomcat 服务器的安装文件下的库文件。deploy.path 变量当前指向 Tomcat 的 web 应用程序文件夹。在 Tomcat 中的应用程序能通过使用 Tomcat 管理应用程序进行启动和停止。管理应用程序的统一资源定位器(URL),用户名和密码也在 build.properties 文件夹中进行指定。 接下来,我们声明一个新的 CLASSPATH 来包含 catalina-ant.jar。 若要通过 Apache Ant 来运行 Tomcat, 这个 jar 文件是必须的。catalina-ant.jar 提供了下述的任务:属性 描述 InstallTask 安装一个 web 应用程序。 类名字为: org.apache.catalina.ant.InstallTask ReloadTask

[1] [2]  下一页


Ant 部署应用