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