利用Ant,将Java工程自动部署到服务器
linuxXml代码http://xace.javaeye.com/images/icon_star.png
[*]<!-- 先将工程文件打包 -->
[*]<tar
destfile="./ant-project/release/xxxxx-online.tgz"
[*] basedir="./ant-project/dist"compression="gzip">
[*]</tar>
[*]
[*]<!-- scp将打包文件上传到linux,停tomcat,删除文件,解压新包 -->
[*]<scp
file="./ant-project/release/xxxxx-online.tgz"
[*] todir="root:xxxxxap@172.16.131.101:/xxxxx/ap/bin/"
trust="true"/>
[*]<sshexec
host="172.16.131.101"
username="tomcat"
password="tomcat"
command="[*] cd /xxxxx/ap/bin;shutdown.sh;rm -rf online;tar zxvf xxxxx-online.tgz;rm -rf online2;[*] cp -rf online online2;rm -rf online3;cp -rf online online3;startup.sh" trust="true"
/>
[*]
[*]<!-- 解压的shell文件,赋予执行权限 -->
[*]<scp
file="./ant-project/release/xxxxx-job.tgz"
[*] todir="root:xxxxxap@172.16.131.101:/xxxxx/ap/"
[*] trust="true"/>
[*]<sshexec
host="172.16.131.101"
username="xxxxx"
password="xxxxx"
[*] command="cd /xxxxx/ap/;tar zxvf xxxxx-job.tgz;cd job/bin;chmod 755 *.sh;cd ../lib;chmod 755 *.dat"
trust="true"/>
[*]
[*]<!-- 重启tomcat -->
[*]<target
name="restart_tomcat">
[*] <sshexec
host="172.16.131.101"
username="tomcat"
password="tomcat"
[*] command="shutdown.sh;sleep 2;startup.sh"
trust="true"
/>
[*]</target>
windows
Xml代码http://xace.javaeye.com/images/icon_star.png
[*]<project
default="tomcat.start"
name="anchannel"
basedir=".">
[*]<property
file="build.properties"
/>
[*]
[*]<target
name="init">
[*] <delete
dir="${temp.dir}"
/>
[*] <mkdir
dir="${temp.dir}"
/>
[*]</target>
[*]
[*]<!-- 从CVS SERVER上取的项目 -->
[*]<target
name="checkout"
depends="init">
[*] <!-- 生成CVS连接的权限信息 -->
[*] <cvspass
cvsroot="${cvsroot}"
password="${cvs.password}"
passfile="${cvs.passfile}"
/>
[*] <echo
message="开始下载src"
/>
[*] <cvs
cvsroot="${cvsroot}"
command="checkout"
package="${cvs.package.src}"
[*] dest="${temp.dir}/cvs_dir"
[*] passfile="${cvs.passfile}"/>
[*] <echo
message="开始下载html"
/>
[*] <cvs
cvsroot="${cvsroot}"
command="checkout"
package="${cvs.package.html}"
[*] dest="${temp.dir}/cvs_dir"
[*] passfile="${cvs.passfile}"
/>
[*] <echo
message="开始下载config"
/>
[*] <cvs
cvsroot="${cvsroot}"
command="checkout"
package="${cvs.package.config}"
[*] dest="${temp.dir}/cvs_dir"
[*] passfile="${cvs.passfile}"
/>
[*]</target>
[*]
[*]<!-- 编译文件 -->
[*]<target
name="compile"
depends="checkout">
[*] <echo
message="开始编译"
/>
[*] <mkdir
dir="${temp.dir}/classes"
/>
[*] <javac
srcdir="${temp.dir}/cvs_dir/${cvs.package.src}"
destdir="${temp.dir}/classes"
failonerror="false"
[*] debug="on"
debuglevel="lines,vars,source"
fork="yes"
memoryInitialSize="256m"
memoryMaximumSize="1024m">
[*] <classpath>
[*] <fileset
dir="${lib.compile.dir}"
includes="*.jar"
/>
[*] <fileset
dir="${lib.project.dir}"
includes="*.jar"
/>
[*] </classpath>
[*] <include
name="**/*.*"
/>
[*] <exclude
name="test/**/*.*"
/>
[*] <exclude
name="**/test/*.*"
/>
[*] <exclude
name="example/**/*.*"
/>
[*] </javac>
[*] <echo
message="编译完成"
/>
[*]</target>
[*]
[*]<!-- 停止tomcat-->
[*]<target
name="tomcat.stop"
depends="compile">
[*] <java
jar="${tomcat.dir}/bin/bootstrap.jar"
fork="true">
[*] <jvmarg
value="-Dcatalina.home=${tomcat.dir}"
/>
[*] <arg
line="stop"
/>
[*] </java>
[*] <delete
dir="${project.dir}"
/>
[*] <mkdir
dir="${project.dir}"
/>
[*]</target>
[*]
[*]<target
name="tomcat.deploy"
depends="tomcat.stop">
[*] <copy
todir="${project.dir}\\WEB-INF\\classes"
overwrite="true">
[*] <fileset
dir="${temp.dir}/classes">
[*] <include
name="**/*.*"
/>
[*] </fileset>
[*] </copy>
[*] <copy
todir="${project.dir}"
overwrite="true">
[*] <fileset
dir="${temp.dir}/cvs_dir/${cvs.package.html}">
[*] <include
name="**/*.*"
/>
[*] </fileset>
[*] </copy>
[*] <copy
todir="${project.dir}\\WEB-INF\\classes"
overwrite="true">
[*] <fileset
dir="${temp.dir}/cvs_dir/${cvs.package.config}">
[*] <include
name="**/*.*"
/>
[*] </fileset>
[*] </copy>
[*] <copy
todir="${project.dir}\\WEB-INF\\lib"
overwrite="true">
[*] <fileset
dir="${lib.project.dir}">
[*] <include
name="**/*.*"
/>
[*] </fileset>
[*] </copy>
[*]</target>
[*]
[*]<!-- 启动tomcat -->
[*]<target
name="tomcat.start"
depends="tomcat.deploy">
[*] <java
jar="${tomcat.dir}/bin/bootstrap.jar"
fork="true">
[*] <jvmarg
value="-Dcatalina.home=${tomcat.dir}"
/>
[*] </java>
[*] <echo
message="Ant任务完成"
/>
[*]</target>
[*]
[*]<!-- [*] <target
name="tomcat.debug">
[*] <java
jar="${tomcat.dir}/bin/bootstrap.jar"
fork="true">
[*] <jvmarg
value="-Dcatalina.home=${tomcat.dir}"
/>
[*] <jvmarg
value="-Xdebug"
/>
[*] <jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
/>
[*] </java>
[*] </target>
[*]
[*] <target
name="stopTomcat">
[*] <exec
dir="${tomcat.dir}/bin"
executable="cmd.exe"
os="Windows 2003">
[*] <arg
line="/c shutdown.bat"
/>
[*] </exec>
[*] </target>
[*]
[*]
[*] <target
name="startTomcat">
[*] <exec
dir="${tomcat.dir}/bin"
executable="cmd.exe"
os="Windows 2003">
[*] <arg
line="/c startup.bat"
/>
[*] </exec>
[*] </target>
[*] -->
[*]</project>
先标记下,回头好好研究
谢分享
页:
[1]