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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<project name="sample project" basedir="." default="usage"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<property name="app.name" value="jLabo"/>
<property name="group.id" value="jLabo"/>
<property name="user" value="tomcat_user" />
<property name="password" value="tomcat_password" />
<property name="local.app.url" value="http://localhost:8080/manager/text" />
<property name="maven.local.repo.dir" value="/home/user/.m2/repository" />
<property name="encoding" value="UTF-8"/>
<property name="ant.home" value="/usr/local/ant"/>
<property name="java.home" value="/usr/local/jdk"/>
<property name="tomcat.home" value="/usr/local/tomcat"/>
<property name="working.dir" value="." />
<property name="package.dir" value="./target/${group.id}"/>
<property name="build.dir" value="./target/classes"/>
<property name="app.server" value="${tomcat.home}/webapps"/>
<property name="app.home" value="${app.server}/${app.name}/"/>
<property name="webinf.home" value="${app.home}/WEB-INF"/>
<property name="class.dir" value="${app.home}/WEB-INF/classes"/>
<property name="libs.dir" value="${app.home}/WEB-INF/lib"/>
<property name="target.jar" value="${app.name}.jar"/>
<property name="cpath" value="
${tomcat.home}/lib/catalina-ant.jar;
${tomcat.home}/lib/tomcat-util.jar;
${tomcat.home}/lib/tomcat-coyote.jar;
"/>
<target name="usage">
<echo message="----USAGE----"/>
<echo message="***targets***"/>
<echo message="update : only pull from git repository"/>
<echo message="build : build (make war project)"/>
<echo message="deploy : deploy to tomcat app directory"/>
<echo message="reload : reload tomcat application"/>
</target>
<macrodef name = "git-command">
<attribute name = "command" />
<attribute name = "dir" default = "" />
<element name = "args" optional = "true" />
<sequential>
<echo message = "git @{command}" />
<exec executable = "git" dir = "@{dir}">
<arg value = "@{command}" />
<args/>
</exec>
</sequential>
</macrodef>
<target name="update">
<git-command command = "pull" dir = "${working.dir}" />
</target>
<artifact:localRepository id="localRepo" path="${maven.local.repo.dir}"/>
<macrodef name="mvn_build">
<attribute name="dir" />
<sequential>
<artifact:mvn pom="@{dir}/pom.xml" fork="yes" failonerror="true">
<localRepository refid="localRepo"/>
<arg value="clean"/>
<arg value="package"/>
</artifact:mvn>
</sequential>
</macrodef>
<target name="build" depends="update">
<mvn_build dir="${working.dir}" />
</target>
<target name="deploy" depends="build">
<!-- deploy to contents -->
<copy todir="${app.home}" preservelastmodified="true">
<fileset dir="${package.dir}">
<!-- ディレクトリ名はアプリ固有なので要調整 -->
<exclude name="WEB-INF/classes/jp/**/*"/>
<exclude name="WEB-INF/classes/jp"/>
</fileset>
</copy>
<jar basedir ="${build.dir}" jarfile ="${libs.dir}/${target.jar}"/>
</target>
<taskdef name="reload" classpath="${cpath}" classname="org.apache.catalina.ant.ReloadTask"/>
<target name="reload" depends="deploy">
<reload url="${local.app.url}"
username="${user}"
password="${password}"
path="/${app.name}"/>
</target>
</project>
|