设为首页 收藏本站
查看: 635|回复: 0

[经验分享] 通用ANT编译发布打包启动tomcat的模板

[复制链接]

尚未签到

发表于 2017-1-29 06:04:35 | 显示全部楼层 |阅读模式
<?xml version="1.0" encoding="UTF-8"?>
<!--
======================================================================
2011-5-6 下午12:37:54  description wu yifeng
======================================================================
-->
<project name="${project.name}" default="deploy" basedir=".">
<!--将name的值改为对应工程的名字将default的值改为需要的缺省任务-->
<!--
app.name 发布的应用名 app.version 版本 build.home 编译目标位置 appserver.home
tomcat根目录位置 deploy.home 部署位置 war.home war包位置 src.home src的位置
src.webroot WebRoot的位置
-->
<property file="build.properties" />
<property name="lib.home" value="${basedir}" />
<property environment="env" />
<property name="java.home" value="S{env.JAVA_HOME}" />
<property name="ant.home" value="S{env.ANT_HOME}" />
<!-- 路径设置 包括了jar文件才能编译-->
<path id="compile.classpath">
<fileset dir="${lib.home}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="test" description="description">
<echo message="project.name=${project.name}" />
<echo message="java.home=${java.home}" />
<echo message="ant.home=${ant.home}" />
<echo message="appserver.home=${appserver.home}" />
<echo message="deploy.path=${deploy.path}" />
<echo message="tomcat.manager.url=${tomcat.manager.url}" />
<echo message="tomcat.manager.username=${tomcat.manager.username}" />
<echo message="tomcat.manager.password=${tomcat.manager.password}" />
<echo message="build.home=${build.home}" />
<echo message="src.webroot=${src.webroot}" />
<echo message="build.web-inf=${build.web-inf}" />
<echo message="build.class=${build.class}" />
<echo message="build.lib=${build.lib}" />
<echo message="src.home=${src.home}" />
<echo message="src.res=${src.res}" />
<echo message="src.lib=${src.lib}" />
<echo message="src.web-inf=${src.web-inf}" />
<echo message="deploy.home=${deploy.home}" />
<echo message="cache.home=${cache.home}" />
</target>
<target name="clean" description="description">
<delete dir="${deploy.home}" failonerror="false" />
<delete dir="${build.home}" failonerror="false" />
<delete file="${deploy.path}/${project.name}.war" failonerror="false" />
</target>
<target name="init" depends="clean">
<mkdir dir="${build.home}" />
<mkdir dir="${build.web-inf}" />
<mkdir dir="${build.class}" />
<mkdir dir="${build.lib}" />
</target>
<target name="prepare" depends="init">
<copy todir="${build.home}">
<fileset dir="${src.webroot}" />
</copy>
</target>
<target name="compile" depends="prepare">
<echo message="start compile!" />
<javac srcdir="${src.home}" destdir="${build.class}" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="$compile.optimize}">
<classpath refid="compile.classpath" />
</javac>
<copy todir="${build.class}">
<fileset dir="${src.res}">
<include name="**" />
</fileset>
</copy>
<echo message="complete compile!" />
</target>
<target name="deploy" depends="compile">
<mkdir dir="${deploy.home}" />
<copy todir="${deploy.home}">
<fileset dir="${build.home}" />
</copy>
<echo message="Successful Deployment" />
</target>
<target name="undeploy">
<delete dir="${deploy.home}" />
<delete dir="${cache.home}" />
<echo message="Successful UnDeployment" />
</target>
<!--
这也是一种打war包的方式
=============================================================================
<target name="jar" depends="compile">
<jar jarfile="${deploy.path}/${project.name}.war" basedir="${build.home}" />
<echo message="Successful packaging jar" />
</target>
=============================================================================
-->
<target name="deploywar" depends="compile" description="deploy the app as the war">
<war destfile="${deploy.path}/${project.name}.war" webxml="${build.web-inf}/web.xml">
<fileset dir="${build.home}">
<include name="**/*.*" />
</fileset>
</war>
</target>
<!--
=============================================================================
打包成jar
=============================================================================
-->
<target name="jar" depends="compile" description="make .jar file">
<delete dir="${doc.home}" />
<mkdir dir="${doc.home}" />
<jar destfile="${doc.home}/${project.name}.jar" basedir="${build.class}">
<manifest>
<attribute name="Specification-Title" value="${project.name}-${doc.title}" />
<attribute name="Created-By" value="吴移风" />
<attribute name="Specification-Version" value="${app.version}" />
<attribute name="Specification-Vendor" value="${doc.vendor}" />
</manifest>
</jar>
</target>
<!--
=============================================================================
输出并打包api文档成rar
=============================================================================
-->
<target name="doc" depends="jar,compile" description="create api doc">
<echo message="Running API Doc ..." />
<tstamp>
<format property="current.year" pattern="yyyy" />
</tstamp>
<javadoc sourcepath="${src.home}" destdir="${doc.home}/${project.name}" author="true" version="true" use="true" doctitle="&lt;h1&gt;${project.name}-${doc.title}-${app.version}&lt;/h1&gt;" windowtitle="${project.name}-${doc.title}-${app.version}" bottom="Copyright &amp;copy; 1998-${current.year} - ${doc.vendor}">
<classpath refid="compile.classpath" />
</javadoc>
<!-- 打包API文件和目录 -->
<echo message="Compressing API Doc ..." />
<zip destfile="${doc.home}/${project.name}-api.rar">
<zipfileset dir="${doc.home}" prefix="${doc.name}" />
</zip>
<!-- 打包之后清除构建的API文件和目录以及classes目录 -->
<echo message="Deleting classes ..." />
<echo message="Deleting API Doc ..." />
</target>
<!--
=============================================================================
tomcat task
=============================================================================
-->
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<target name="install" description="install the application in Tomcat">
<install url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="${project.name}" war="${project.name}" />
</target>
<target name="reload" description="reload the application in Tomcat">
<reload url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="${project.name}" />
</target>
<target name="list" description="list All the application in Tomcat">
<list url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" />
</target>
<target name="start" description="start the application in Tomcat">
<start url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${project.name}" />
</target>
<target name="stop" description="stop the application in Tomcat">
<stop url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/PiccSystem" />
</target>
<!--
=============================================================================
start tomcat
=============================================================================
-->
<target name="start-tomcat-E">
<exec executable="cmd" dir="${appserver.home}/bin">
<arg value="/c" />
<arg value="startup.bat" />
</exec>
</target>
<target name="stop-tomcat-E">
<exec executable="cmd " dir="${appserver.home}/bin" spawn="true">
<arg value="/c" />
<arg value="shutdown.bat" />
</exec>
</target>
<target name="start-tomcat-D">
<exec executable="cmd" dir="${casserver.home}/bin">
<arg value="/c" />
<arg value="startup.bat" />
</exec>
</target>
<target name="stop-tomcat-D">
<exec executable="cmd " dir="${casserver.home}/bin" spawn="true">
<arg value="/c" />
<arg value="shutdown.bat" />
</exec>
</target>
</project>



project.name=PiccSystem
#----------------------------------------------------------  
appserver.home=E:/apache-tomcat-6.0.14
casserver.home=D:/apache-tomcat-6.0.14
deploy.path=E:/apache-tomcat-6.0.14/webapps
tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=admin
tomcat.manager.password=manager
build.home=build
#------
app.version=1.0
build.web-inf=build/WEB-INF
build.class=build/WEB-INF/classes
build.lib=build/WEB-INF/lib
src.webroot=WebRoot
src.home=src/main/java
src.res=src/main/resources
src.lib=WebRoot/WEB-INF/lib
src.web-inf=WebRoot/WEB-INF
deploy.home=E:/apache-tomcat-6.0.14/webapps/PiccSystem
cache.home=E:/apache-tomcat-6.0.14/work/Catalina/localhost
doc.home=E:/doc
doc.title=API
doc.vendor=Stone Age Co. Ltd.
compile.debug=true
compile.deprecation=false
compile.optimize=true

说明:提供编译,发布到tomcat,打war包。启动tomcat,停止tomcat,我这里使用的是eclipse,所以编译路径是build,如果你不是请相应修改,project.name是发布到tomcat的名称,还有WebRoot/WebContent,就是这些目录,大家如果有不同,修改properties文件就好了。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-334634-1-1.html 上篇帖子: Tomcat 6.0.24与EclipseEE 3.5.1 下篇帖子: Eclipse3.6中免安装版Tomcat的安装配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表