发布时间:2014-09-05 17:10:07作者:知识屋
使用linux系统上ant工具,让java web项目项目定时更新tomcat,实现过程自动化
build.properties
build.version=1.8.2 includeantruntime=on svnant.jar=/jdk/jar/svnant.jar svnClientAdapter.jar=/jdk/jar/svnClientAdapter.jar svnjavahl.jar=/jdk/jar/svnjavahl.jar javaEE1.4.lib= /usr/java/jdk1.6.0_18/lib debuglevel=source,lines target=1.6 source=1.6 work.space=/jdk/workspace dist.dir=${work.space} build.dir=${work.space}/WebRoot/WEB-INF/classes lib.dir=${work.space}/WebRoot/WEB-INF/lib java.source=${work.space}/src java.config=${work.space}/src/config web.dir=${work.space}/WebRoot resource.dir=${work.space}/resources tomcat.home=/usr/java/apache-tomcat-6.0.32/ war.file=${dist.dir}/${ant.project.name}.war urlRepos=http://www.abc.com/
build.xml
<project basedir="." name="ROOT" default="auto"> <!-- all properties are in build.properties --> <property file="build.properties" /> <!--svn本身需要的运行库 --> <path id="svnant.lib"> <pathelement location="${svnjavahl.jar}" /> <pathelement location="${svnant.jar}" /> <pathelement location="${svnClientAdapter.jar}" /> </path> <!--java EE 1.4 库 --> <path id="javaEE1.4"> <fileset dir="${javaEE1.4.lib}"> <include name="**/*.jar" /> </fileset> </path> <path id="tomcat6.0.32"> <fileset dir="${tomcat.home}"> <include name="**/*.jar" /> </fileset> </path> <!--项目的classpath库 --> <path id="project.classpath"> <pathelement location="${build.dir}" /> <fileset dir="${lib.dir}" > <!-- <include name="**/*.jar" />--> </fileset> </path> <!--清理项目任务(干掉下载目录,tomcat原来的部署文件) --> <target name="clear"> <delete dir="${work.space}" /> <delete dir="${tomcat.home}/work/Catalina/localhost/${ant.project.name}" /> <delete dir="${tomcat.home}/webapps/${ant.project.name}" /> <delete dir="${tomcat.home}/webapps/${ant.project.name}.war" /> </target> <!-- load the svn task --> <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.lib" /> <!--svn同步任务--> <target name="svn" depends="clear"> <mkdir dir="${work.space}"/> <svn username="xxxxx" password="xxxxx" javahl="false"> <checkout url="${urlRepos}" destPath="${work.space}" /> </svn> </target> <!--编译--> <target name="compile" depends="svn" description="======compile project======"> <echo message="compile==========>${ant.project.name}: ${ant.file}" /> <mkdir dir="${build.dir}" /> <copy includeemptydirs="false" todir="${build.dir}"> <fileset dir="${java.source}" excludes="**/*.launch, **/*.java, config/*.*"/> </copy> <copy includeemptydirs="false" todir="${build.dir}"> <fileset dir="${java.config}" excludes="**/*.launch, **/*.java"/> </copy> <javac includeantruntime="false" includejavaruntime="true" debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" source="${source}" target="${target}" encoding="utf-8"> <src path="${java.source}" /> <exclude name="config/"/> <classpath> <path refid="project.classpath"> </path> <path refid="javaEE1.4"> </path> <path refid="tomcat6.0.32"> </path> </classpath> <compilerarg value="-Xlint:unchecked"/> <compilerarg value="-Xlint:deprecation"/> </javac> <!-- <javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" source="${source}" target="${target}" encoding="utf-8"> <src path="${java.config}" /> </javac> --> </target> <!--压缩,打包--> <target name="war" depends="compile" description="======compress j2ee war file======"> <mkdir dir="${dist.dir}" /> <!--compress j2ee war file--> <war destfile="${war.file}" webxml="${web.dir}/WEB-INF/web.xml"> <fileset dir="${web.dir}" /> <classes dir="${build.dir}" /> <lib dir="${lib.dir}" /> </war> </target> <!--shutdowntomcat--> <target name="shutdowntomcat" description="========shutdowntomcat==========="> <exec executable="${tomcat.home}/bin/shutdown.sh" failonerror="false"></exec> <sleep seconds="10"/> </target> <!--startuptomcat--> <target name="startuptomcat" description="========startuptomcat==========="> <sleep seconds="5"/> <exec executable="${tomcat.home}/bin/startup.sh" failonerror="false"></exec> </target> <!--部署到tomcat下面克--> <target name="deploy" depends="war"> <copy file="${war.file}" todir="${tomcat.home}/webapps" /> </target> <!--全自动无敌部署,启动关闭tomcat--> <target name="auto" depends="shutdowntomcat,deploy,startuptomcat"> <echo message="DONE!!!!" /> </target> </project>
build.sh
#! /bin/sh JAVA_HOME=/usr/java/jdk1.6.0_18 ANT_HOME=/usr/java/apache-ant-1.8.2 PATH=$ANT_HOME/bin:$JAVA_HOME/bin:$PATH cd /jdk /usr/java/apache-ant-1.8.2/bin/ant -f /jdk/build.xml > /jdk/ant-build.log 2>&1
crontab -e
25,50 * * * * /jdk/build.sh
linux一键安装web环境全攻略 在linux系统中怎么一键安装web环境方法
Linux网络基本网络配置方法介绍 如何配置Linux系统的网络方法
Linux下DNS服务器搭建详解 Linux下搭建DNS服务器和配置文件
对Linux进行详细的性能监控的方法 Linux 系统性能监控命令详解
linux系统root密码忘了怎么办 linux忘记root密码后找回密码的方法
Linux基本命令有哪些 Linux系统常用操作命令有哪些
Linux必学的网络操作命令 linux网络操作相关命令汇总
linux系统从入侵到提权的详细过程 linux入侵提权服务器方法技巧
linux系统怎么用命令切换用户登录 Linux切换用户的命令是什么
在linux中添加普通新用户登录 如何在Linux中添加一个新的用户
2012-07-10
CentOS 6.3安装(详细图解教程)
Linux怎么查看网卡驱动?Linux下查看网卡的驱动程序
centos修改主机名命令
Ubuntu或UbuntuKyKin14.04Unity桌面风格与Gnome桌面风格的切换
FEDORA 17中设置TIGERVNC远程访问
StartOS 5.0相关介绍,新型的Linux系统!
解决vSphere Client登录linux版vCenter失败
LINUX最新提权 Exploits Linux Kernel <= 2.6.37
nginx在网站中的7层转发功能