1 | <!-- |
---|
2 | Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | contributor license agreements. See the NOTICE file distributed with |
---|
4 | this work for additional information regarding copyright ownership. |
---|
5 | The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | (the "License"); you may not use this file except in compliance with |
---|
7 | the License. You may obtain a copy of the License at |
---|
8 | |
---|
9 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | |
---|
11 | Unless required by applicable law or agreed to in writing, software |
---|
12 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | See the License for the specific language governing permissions and |
---|
15 | limitations under the License. |
---|
16 | --> |
---|
17 | |
---|
18 | <!-- |
---|
19 | General purpose build script for web applications and web services, |
---|
20 | including enhanced support for deploying directly to a Tomcat 6 |
---|
21 | based server. |
---|
22 | |
---|
23 | This build script assumes that the source code of your web application |
---|
24 | is organized into the following subdirectories underneath the source |
---|
25 | code directory from which you execute the build script: |
---|
26 | |
---|
27 | docs Static documentation files to be copied to |
---|
28 | the "docs" subdirectory of your distribution. |
---|
29 | |
---|
30 | src Java source code (and associated resource files) |
---|
31 | to be compiled to the "WEB-INF/classes" |
---|
32 | subdirectory of your web applicaiton. |
---|
33 | |
---|
34 | web Static HTML, JSP, and other content (such as |
---|
35 | image files), including the WEB-INF subdirectory |
---|
36 | and its configuration file contents. |
---|
37 | |
---|
38 | $Id: build.xml.txt 562814 2007-08-05 03:52:04Z markt $ |
---|
39 | --> |
---|
40 | |
---|
41 | |
---|
42 | <!-- A "project" describes a set of targets that may be requested |
---|
43 | when Ant is executed. The "default" attribute defines the |
---|
44 | target which is executed if no specific target is requested, |
---|
45 | and the "basedir" attribute defines the current working directory |
---|
46 | from which Ant executes the requested task. This is normally |
---|
47 | set to the current working directory. |
---|
48 | --> |
---|
49 | |
---|
50 | <project name="My Project" default="compile" basedir="."> |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | <!-- ===================== Property Definitions =========================== --> |
---|
55 | |
---|
56 | |
---|
57 | <!-- |
---|
58 | |
---|
59 | Each of the following properties are used in the build script. |
---|
60 | Values for these properties are set by the first place they are |
---|
61 | defined, from the following list: |
---|
62 | |
---|
63 | * Definitions on the "ant" command line (ant -Dfoo=bar compile). |
---|
64 | |
---|
65 | * Definitions from a "build.properties" file in the top level |
---|
66 | source directory of this application. |
---|
67 | |
---|
68 | * Definitions from a "build.properties" file in the developer's |
---|
69 | home directory. |
---|
70 | |
---|
71 | * Default definitions in this build.xml file. |
---|
72 | |
---|
73 | You will note below that property values can be composed based on the |
---|
74 | contents of previously defined properties. This is a powerful technique |
---|
75 | that helps you minimize the number of changes required when your development |
---|
76 | environment is modified. Note that property composition is allowed within |
---|
77 | "build.properties" files as well as in the "build.xml" script. |
---|
78 | |
---|
79 | --> |
---|
80 | |
---|
81 | <property file="build.properties"/> |
---|
82 | <property file="${user.home}/build.properties"/> |
---|
83 | |
---|
84 | |
---|
85 | <!-- ==================== File and Directory Names ======================== --> |
---|
86 | |
---|
87 | |
---|
88 | <!-- |
---|
89 | |
---|
90 | These properties generally define file and directory names (or paths) that |
---|
91 | affect where the build process stores its outputs. |
---|
92 | |
---|
93 | app.name Base name of this application, used to |
---|
94 | construct filenames and directories. |
---|
95 | Defaults to "myapp". |
---|
96 | |
---|
97 | app.path Context path to which this application should be |
---|
98 | deployed (defaults to "/" plus the value of the |
---|
99 | "app.name" property). |
---|
100 | |
---|
101 | app.version Version number of this iteration of the application. |
---|
102 | |
---|
103 | build.home The directory into which the "prepare" and |
---|
104 | "compile" targets will generate their output. |
---|
105 | Defaults to "build". |
---|
106 | |
---|
107 | catalina.home The directory in which you have installed |
---|
108 | a binary distribution of Tomcat 6. This will |
---|
109 | be used by the "deploy" target. |
---|
110 | |
---|
111 | dist.home The name of the base directory in which |
---|
112 | distribution files are created. |
---|
113 | Defaults to "dist". |
---|
114 | |
---|
115 | manager.password The login password of a user that is assigned the |
---|
116 | "manager" role (so that he or she can execute |
---|
117 | commands via the "/manager" web application) |
---|
118 | |
---|
119 | manager.url The URL of the "/manager" web application on the |
---|
120 | Tomcat installation to which we will deploy web |
---|
121 | applications and web services. |
---|
122 | |
---|
123 | manager.username The login username of a user that is assigned the |
---|
124 | "manager" role (so that he or she can execute |
---|
125 | commands via the "/manager" web application) |
---|
126 | |
---|
127 | --> |
---|
128 | |
---|
129 | <property name="app.name" value="myapp"/> |
---|
130 | <property name="app.path" value="/${app.name}"/> |
---|
131 | <property name="app.version" value="0.1-dev"/> |
---|
132 | <property name="build.home" value="${basedir}/build"/> |
---|
133 | <property name="catalina.home" value="../../../.."/> <!-- UPDATE THIS! --> |
---|
134 | <property name="dist.home" value="${basedir}/dist"/> |
---|
135 | <property name="docs.home" value="${basedir}/docs"/> |
---|
136 | <property name="manager.url" value="http://localhost:8080/manager"/> |
---|
137 | <property name="src.home" value="${basedir}/src"/> |
---|
138 | <property name="web.home" value="${basedir}/web"/> |
---|
139 | |
---|
140 | |
---|
141 | <!-- ==================== External Dependencies =========================== --> |
---|
142 | |
---|
143 | |
---|
144 | <!-- |
---|
145 | |
---|
146 | Use property values to define the locations of external JAR files on which |
---|
147 | your application will depend. In general, these values will be used for |
---|
148 | two purposes: |
---|
149 | * Inclusion on the classpath that is passed to the Javac compiler |
---|
150 | * Being copied into the "/WEB-INF/lib" directory during execution |
---|
151 | of the "deploy" target. |
---|
152 | |
---|
153 | Because we will automatically include all of the Java classes that Tomcat 6 |
---|
154 | exposes to web applications, we will not need to explicitly list any of those |
---|
155 | dependencies. You only need to worry about external dependencies for JAR |
---|
156 | files that you are going to include inside your "/WEB-INF/lib" directory. |
---|
157 | |
---|
158 | --> |
---|
159 | |
---|
160 | <!-- Dummy external dependency --> |
---|
161 | <!-- |
---|
162 | <property name="foo.jar" |
---|
163 | value="/path/to/foo.jar"/> |
---|
164 | --> |
---|
165 | |
---|
166 | |
---|
167 | <!-- ==================== Compilation Classpath =========================== --> |
---|
168 | |
---|
169 | <!-- |
---|
170 | |
---|
171 | Rather than relying on the CLASSPATH environment variable, Ant includes |
---|
172 | features that makes it easy to dynamically construct the classpath you |
---|
173 | need for each compilation. The example below constructs the compile |
---|
174 | classpath to include the servlet.jar file, as well as the other components |
---|
175 | that Tomcat makes available to web applications automatically, plus anything |
---|
176 | that you explicitly added. |
---|
177 | |
---|
178 | --> |
---|
179 | |
---|
180 | <path id="compile.classpath"> |
---|
181 | |
---|
182 | <!-- Include all JAR files that will be included in /WEB-INF/lib --> |
---|
183 | <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** --> |
---|
184 | <!-- |
---|
185 | <pathelement location="${foo.jar}"/> |
---|
186 | --> |
---|
187 | |
---|
188 | <!-- Include all elements that Tomcat exposes to applications --> |
---|
189 | <fileset dir="${catalina.home}/bin"> |
---|
190 | <include name="*.jar"/> |
---|
191 | </fileset> |
---|
192 | <pathelement location="${catalina.home}/lib"/> |
---|
193 | <fileset dir="${catalina.home}/lib"> |
---|
194 | <include name="*.jar"/> |
---|
195 | </fileset> |
---|
196 | |
---|
197 | </path> |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | <!-- ================== Custom Ant Task Definitions ======================= --> |
---|
202 | |
---|
203 | |
---|
204 | <!-- |
---|
205 | |
---|
206 | These properties define custom tasks for the Ant build tool that interact |
---|
207 | with the "/manager" web application installed with Tomcat 6. Before they |
---|
208 | can be successfully utilized, you must perform the following steps: |
---|
209 | |
---|
210 | - Copy the file "lib/catalina-ant.jar" from your Tomcat 6 |
---|
211 | installation into the "lib" directory of your Ant installation. |
---|
212 | |
---|
213 | - Create a "build.properties" file in your application's top-level |
---|
214 | source directory (or your user login home directory) that defines |
---|
215 | appropriate values for the "manager.password", "manager.url", and |
---|
216 | "manager.username" properties described above. |
---|
217 | |
---|
218 | For more information about the Manager web application, and the functionality |
---|
219 | of these tasks, see <http://localhost:8080/tomcat-docs/manager-howto.html>. |
---|
220 | |
---|
221 | --> |
---|
222 | |
---|
223 | <taskdef resource="org/apache/catalina/ant/catalina.tasks" |
---|
224 | classpathref="compile.classpath"/> |
---|
225 | |
---|
226 | |
---|
227 | <!-- ==================== Compilation Control Options ==================== --> |
---|
228 | |
---|
229 | <!-- |
---|
230 | |
---|
231 | These properties control option settings on the Javac compiler when it |
---|
232 | is invoked using the <javac> task. |
---|
233 | |
---|
234 | compile.debug Should compilation include the debug option? |
---|
235 | |
---|
236 | compile.deprecation Should compilation include the deprecation option? |
---|
237 | |
---|
238 | compile.optimize Should compilation include the optimize option? |
---|
239 | |
---|
240 | --> |
---|
241 | |
---|
242 | <property name="compile.debug" value="true"/> |
---|
243 | <property name="compile.deprecation" value="false"/> |
---|
244 | <property name="compile.optimize" value="true"/> |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | <!-- ==================== All Target ====================================== --> |
---|
249 | |
---|
250 | <!-- |
---|
251 | |
---|
252 | The "all" target is a shortcut for running the "clean" target followed |
---|
253 | by the "compile" target, to force a complete recompile. |
---|
254 | |
---|
255 | --> |
---|
256 | |
---|
257 | <target name="all" depends="clean,compile" |
---|
258 | description="Clean build and dist directories, then compile"/> |
---|
259 | |
---|
260 | |
---|
261 | |
---|
262 | <!-- ==================== Clean Target ==================================== --> |
---|
263 | |
---|
264 | <!-- |
---|
265 | |
---|
266 | The "clean" target deletes any previous "build" and "dist" directory, |
---|
267 | so that you can be ensured the application can be built from scratch. |
---|
268 | |
---|
269 | --> |
---|
270 | |
---|
271 | <target name="clean" |
---|
272 | description="Delete old build and dist directories"> |
---|
273 | <delete dir="${build.home}"/> |
---|
274 | <delete dir="${dist.home}"/> |
---|
275 | </target> |
---|
276 | |
---|
277 | |
---|
278 | |
---|
279 | <!-- ==================== Compile Target ================================== --> |
---|
280 | |
---|
281 | <!-- |
---|
282 | |
---|
283 | The "compile" target transforms source files (from your "src" directory) |
---|
284 | into object files in the appropriate location in the build directory. |
---|
285 | This example assumes that you will be including your classes in an |
---|
286 | unpacked directory hierarchy under "/WEB-INF/classes". |
---|
287 | |
---|
288 | --> |
---|
289 | |
---|
290 | <target name="compile" depends="prepare" |
---|
291 | description="Compile Java sources"> |
---|
292 | |
---|
293 | <!-- Compile Java classes as necessary --> |
---|
294 | <mkdir dir="${build.home}/WEB-INF/classes"/> |
---|
295 | <javac srcdir="${src.home}" |
---|
296 | destdir="${build.home}/WEB-INF/classes" |
---|
297 | debug="${compile.debug}" |
---|
298 | deprecation="${compile.deprecation}" |
---|
299 | optimize="${compile.optimize}"> |
---|
300 | <classpath refid="compile.classpath"/> |
---|
301 | </javac> |
---|
302 | |
---|
303 | <!-- Copy application resources --> |
---|
304 | <copy todir="${build.home}/WEB-INF/classes"> |
---|
305 | <fileset dir="${src.home}" excludes="**/*.java"/> |
---|
306 | </copy> |
---|
307 | |
---|
308 | </target> |
---|
309 | |
---|
310 | |
---|
311 | |
---|
312 | <!-- ==================== Dist Target ===================================== --> |
---|
313 | |
---|
314 | |
---|
315 | <!-- |
---|
316 | |
---|
317 | The "dist" target creates a binary distribution of your application |
---|
318 | in a directory structure ready to be archived in a tar.gz or zip file. |
---|
319 | Note that this target depends on two others: |
---|
320 | |
---|
321 | * "compile" so that the entire web application (including external |
---|
322 | dependencies) will have been assembled |
---|
323 | |
---|
324 | * "javadoc" so that the application Javadocs will have been created |
---|
325 | |
---|
326 | --> |
---|
327 | |
---|
328 | <target name="dist" depends="compile,javadoc" |
---|
329 | description="Create binary distribution"> |
---|
330 | |
---|
331 | <!-- Copy documentation subdirectories --> |
---|
332 | <mkdir dir="${dist.home}/docs"/> |
---|
333 | <copy todir="${dist.home}/docs"> |
---|
334 | <fileset dir="${docs.home}"/> |
---|
335 | </copy> |
---|
336 | |
---|
337 | <!-- Create application JAR file --> |
---|
338 | <jar jarfile="${dist.home}/${app.name}-${app.version}.war" |
---|
339 | basedir="${build.home}"/> |
---|
340 | |
---|
341 | <!-- Copy additional files to ${dist.home} as necessary --> |
---|
342 | |
---|
343 | </target> |
---|
344 | |
---|
345 | |
---|
346 | |
---|
347 | <!-- ==================== Install Target ================================== --> |
---|
348 | |
---|
349 | <!-- |
---|
350 | |
---|
351 | The "install" target tells the specified Tomcat 6 installation to dynamically |
---|
352 | install this web application and make it available for execution. It does |
---|
353 | *not* cause the existence of this web application to be remembered across |
---|
354 | Tomcat restarts; if you restart the server, you will need to re-install all |
---|
355 | this web application. |
---|
356 | |
---|
357 | If you have already installed this application, and simply want Tomcat to |
---|
358 | recognize that you have updated Java classes (or the web.xml file), use the |
---|
359 | "reload" target instead. |
---|
360 | |
---|
361 | NOTE: This target will only succeed if it is run from the same server that |
---|
362 | Tomcat is running on. |
---|
363 | |
---|
364 | NOTE: This is the logical opposite of the "remove" target. |
---|
365 | |
---|
366 | --> |
---|
367 | |
---|
368 | <target name="install" depends="compile" |
---|
369 | description="Install application to servlet container"> |
---|
370 | |
---|
371 | <deploy url="${manager.url}" |
---|
372 | username="${manager.username}" |
---|
373 | password="${manager.password}" |
---|
374 | path="${app.path}" |
---|
375 | localWar="file://${build.home}"/> |
---|
376 | |
---|
377 | </target> |
---|
378 | |
---|
379 | |
---|
380 | <!-- ==================== Javadoc Target ================================== --> |
---|
381 | |
---|
382 | <!-- |
---|
383 | |
---|
384 | The "javadoc" target creates Javadoc API documentation for the Java |
---|
385 | classes included in your application. Normally, this is only required |
---|
386 | when preparing a distribution release, but is available as a separate |
---|
387 | target in case the developer wants to create Javadocs independently. |
---|
388 | |
---|
389 | --> |
---|
390 | |
---|
391 | <target name="javadoc" depends="compile" |
---|
392 | description="Create Javadoc API documentation"> |
---|
393 | |
---|
394 | <mkdir dir="${dist.home}/docs/api"/> |
---|
395 | <javadoc sourcepath="${src.home}" |
---|
396 | destdir="${dist.home}/docs/api" |
---|
397 | packagenames="*"> |
---|
398 | <classpath refid="compile.classpath"/> |
---|
399 | </javadoc> |
---|
400 | |
---|
401 | </target> |
---|
402 | |
---|
403 | |
---|
404 | |
---|
405 | <!-- ====================== List Target =================================== --> |
---|
406 | |
---|
407 | <!-- |
---|
408 | |
---|
409 | The "list" target asks the specified Tomcat 6 installation to list the |
---|
410 | currently running web applications, either loaded at startup time or |
---|
411 | installed dynamically. It is useful to determine whether or not the |
---|
412 | application you are currently developing has been installed. |
---|
413 | |
---|
414 | --> |
---|
415 | |
---|
416 | <target name="list" |
---|
417 | description="List installed applications on servlet container"> |
---|
418 | |
---|
419 | <list url="${manager.url}" |
---|
420 | username="${manager.username}" |
---|
421 | password="${manager.password}"/> |
---|
422 | |
---|
423 | </target> |
---|
424 | |
---|
425 | |
---|
426 | <!-- ==================== Prepare Target ================================== --> |
---|
427 | |
---|
428 | <!-- |
---|
429 | |
---|
430 | The "prepare" target is used to create the "build" destination directory, |
---|
431 | and copy the static contents of your web application to it. If you need |
---|
432 | to copy static files from external dependencies, you can customize the |
---|
433 | contents of this task. |
---|
434 | |
---|
435 | Normally, this task is executed indirectly when needed. |
---|
436 | |
---|
437 | --> |
---|
438 | |
---|
439 | <target name="prepare"> |
---|
440 | |
---|
441 | <!-- Create build directories as needed --> |
---|
442 | <mkdir dir="${build.home}"/> |
---|
443 | <mkdir dir="${build.home}/WEB-INF"/> |
---|
444 | <mkdir dir="${build.home}/WEB-INF/classes"/> |
---|
445 | |
---|
446 | |
---|
447 | <!-- Copy static content of this web application --> |
---|
448 | <copy todir="${build.home}"> |
---|
449 | <fileset dir="${web.home}"/> |
---|
450 | </copy> |
---|
451 | |
---|
452 | <!-- Copy external dependencies as required --> |
---|
453 | <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** --> |
---|
454 | <mkdir dir="${build.home}/WEB-INF/lib"/> |
---|
455 | <!-- |
---|
456 | <copy todir="${build.home}/WEB-INF/lib" file="${foo.jar}"/> |
---|
457 | --> |
---|
458 | |
---|
459 | <!-- Copy static files from external dependencies as needed --> |
---|
460 | <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** --> |
---|
461 | |
---|
462 | </target> |
---|
463 | |
---|
464 | |
---|
465 | <!-- ==================== Reload Target =================================== --> |
---|
466 | |
---|
467 | <!-- |
---|
468 | |
---|
469 | The "reload" signals the specified application Tomcat 6 to shut itself down |
---|
470 | and reload. This can be useful when the web application context is not |
---|
471 | reloadable and you have updated classes or property files in the |
---|
472 | /WEB-INF/classes directory or when you have added or updated jar files in the |
---|
473 | /WEB-INF/lib directory. |
---|
474 | |
---|
475 | NOTE: The /WEB-INF/web.xml web application configuration file is not reread |
---|
476 | on a reload. If you have made changes to your web.xml file you must stop |
---|
477 | then start the web application. |
---|
478 | |
---|
479 | --> |
---|
480 | |
---|
481 | <target name="reload" depends="compile" |
---|
482 | description="Reload application on servlet container"> |
---|
483 | |
---|
484 | <reload url="${manager.url}" |
---|
485 | username="${manager.username}" |
---|
486 | password="${manager.password}" |
---|
487 | path="${app.path}"/> |
---|
488 | |
---|
489 | </target> |
---|
490 | |
---|
491 | |
---|
492 | <!-- ==================== Remove Target =================================== --> |
---|
493 | |
---|
494 | <!-- |
---|
495 | |
---|
496 | The "remove" target tells the specified Tomcat 6 installation to dynamically |
---|
497 | remove this web application from service. |
---|
498 | |
---|
499 | NOTE: This is the logical opposite of the "install" target. |
---|
500 | |
---|
501 | --> |
---|
502 | |
---|
503 | <target name="remove" |
---|
504 | description="Remove application on servlet container"> |
---|
505 | |
---|
506 | <undeploy url="${manager.url}" |
---|
507 | username="${manager.username}" |
---|
508 | password="${manager.password}" |
---|
509 | path="${app.path}"/> |
---|
510 | |
---|
511 | </target> |
---|
512 | |
---|
513 | |
---|
514 | </project> |
---|