Ant脚本杀掉Tomcat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?xml version="1.0" encoding="UTF-8" ?>
<project name="项目名" basedir="." default="deploy">
<property name="src.dir" value="src"/>
<property name="web.dir" value="web"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="tomcat.name" value="Tomcat目录名"/>
<property name="tomcat.path" value="Tomcat路径"/>
<property name="deploy.path" value="${tomcat.path}/webapps"/>
<property name="war.name" value="war包"/>
<property name="jdk.version" value="1.8"/>

<path id="classpath">
<fileset dir="${web.dir}/WEB-INF/lib" includes="*.jar"/>
<pathelement path="${build.dir}"/>
</path>

<target name="clean">
<echo message="clean start..."/>
<delete>
<fileset dir="${build.dir}">
<include name="**/*.class"/>
</fileset>
</delete>
<echo message="clean end..."/>
</target>

<target name="build" depends="clean">
<echo message="build start..."/>
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="${jdk.version}" target="${jdk.version}" includeantruntime="true" nowarn="true">
<src path="${src.dir}"/>
<classpath refid="classpath"/>
</javac>
<echo message="build end..."/>
</target>

<target name="war" depends="build">
<echo message="pack war start..."/>
<tstamp>
<format property="date" pattern="yyyy_MM_dd"/>
</tstamp>
<war destfile="自定义名字_${date}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
<classes dir="${build.dir}"/>
</war>
<echo message="pack war end..."/>
<echo message="copy war start..."/>
<copy tofile="${deploy.path}/${war.name}" preservelastmodified="true" overwrite="true">
<fileset dir=".">
<include name="自定义名字${date}.war"/>
</fileset>
</copy>
<echo message="copy war end..."/>
</target>

<target name="deploy" depends="war">
<echo message="shutdown tomcat start..."/>
<exec executable="/bin/zsh">
<arg value="-c"/>
<arg value="ps x | grep tomcat | grep -v grep | awk '{print $1}' | xargs kill -9 &amp; > /dev/null"/>
</exec>
<echo message="shutdown tomcat end..."/>
<echo message="startup tomcat start..."/>
<exec executable="/bin/zsh">
<arg value="${tomcat.path}/bin/startup.sh"/>
</exec>
<echo message="startup tomcat end..."/>
</target>
</project>