DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4917>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4917

Better build.xml for tomcat application developers guide

           Summary: Better build.xml for tomcat application developers guide
           Product: Tomcat 4
           Version: 4.0.1 Final
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Unknown
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


I've been training up developers using an example project based on the 
build.xml in the tomcat developer's guide and the struts sample application.
I've found that there are some duplication issues in the sample build.xml 
which invite errors and increase maintenance. 

There are a couple of bugs with the stated functionality (e.g. in where 
properties are loaded from) but the main issue is with the separate definition 
of compile.classpath . This requires developers to maintain not only the 
classpath but an identical list of files to be copied into the distribution. 
The (working) build.xml below is a rearrangement of the example in the 
documentation to fix these issues, and to make the build work 'out of 
the box' for more projects. See initialled comments ('BE') in the file for more
details.

<!-- A "project" describes a set of targets that may be requested
     when Ant is executed.  The "default" attribute defines the
     target which is executed if no specific target is requested,
     and the "basedir" attribute defines the current working directory
     from which Ant executes the requested task.  This is normally
     set to the current working directory.
-->


<project name="My Project" default="compile" basedir=".">



<!-- ===================== Property Definitions =========================== -->

<!--

  Each of the following properties are used in the build script.
  Values for these properties are set by the first place they are
  defined, from the following list:
  * Definitions on the "ant" command line (ant -Dcatalina.home=xyz compile)
  * Definitions from a "build.properties" file in the top level
    source directory
  * Definitions from a "build.properties" file in the developer's
    home directory
  * Default definitions in this build.xml file

  You will note below that property values can be composed based on the
  contents of previously defined properties.  This is a powerful technique
  that helps you minimize the number of changes required when your development
  environment is modified.  Note that property composition is allowed within
  "build.properties" files as well as in the "build.xml" script.

-->
  <!-- BE: added lines below to make the statements above true!! -->
  <property file="build.properties"/>
  <property file="${user.home}/build.properties"/>
 


<!-- ==================== File and Directory Names ======================== -->

<!--

  These properties generally define file and directory names (or paths) that
  affect where the build process stores its outputs.

  app.name             Base name of this application, used to
                       construct filenames and directories.
                       Defaults to "myapp".

  app.version          Version identifier for this application.

  build.home           The directory into which the "prepare" and
                       "compile" targets will generate their output.
                       Defaults to "build".

  catalina.home        The directory in which you have installed
                       a binary distribution of Tomcat 4.  This will
                       be used by the "deploy" target.

  deploy.home          The name of the directory into which the
                       deployment hierarchy will be created, and into
                       which the build directory will be copied.
                       Defaults to "${catalina.home}/webapps/${app.name}".

  dist.home            The name of the base directory in which
                       distribution files are created.
                       Defaults to "dist".

-->

  <property name="app.name"      value="myapp"/>
  <property name="app.version"   value="1.0"/>
  <property name="build.home"    value="build"/>
  <!-- BE: set to default path used by tomcat installer. That way it works out 
of the box for some -->
  <property name="catalina.home" value="C:/Program Files/Apache Tomcat 4.0"/> 
<!-- UPDATE THIS! -->
  <property name="deploy.home"   value="${catalina.home}/webapps/${app.name}"/>
  <property name="dist.home"     value="dist"/>



<!--  ==================== Compilation Control Options ==================== -->

<!--

  These properties control option settings on the Javac compiler when it
  is invoked using the <javac> task.

  compile.debug        Should compilation include the debug option?

  compile.deprecation  Should compilation include the deprecation option?

  compile.optimize     Should compilation include the optimize option?

-->

  <property name="compile.debug"       value="true"/>
  <property name="compile.deprecation" value="false"/>
  <property name="compile.optimize"    value="true"/>



<!-- ==================== External Dependencies =========================== -->


<!--

  Use property values to define the locations of external JAR files on which
  your application will depend.  In general, these values will be used for
  two purposes:
  * Inclusion on the classpath that is passed to the Javac compiler
  * Being copied into the "/WEB-INF/lib" directory during execution
    of the "deploy" target.

  Because we will automatically include all of the Java classes that Tomcat 4
  exposes to web applications, we will not need to explicitly list any of those
  dependencies.  You only need to worry about external dependencies for JAR
  files that you are going to include inside your "/WEB-INF/lib" directory.

-->

<!-- Dummy external dependency -->
<!--
  <property name="foo.jar"
           value="/path/to/foo.jar"/>
-->





<!-- ==================== All Target ====================================== -->

<!--

  The "all" target is a shortcut for running the "clean" target followed
  by the "compile" target, to force a complete recompile.

-->

  <target name="all" depends="clean,compile"
   description="Clean build and dist, then compile"/>



<!-- ==================== Clean Target ==================================== -->

<!--

  The "clean" target deletes any previous "build" and "dist" directory,
  so that you can be ensured the application can be built from scratch.

-->

  <target name="clean"
   description="Delete old build and dist directories">
    <delete dir="${build.home}"/>
    <delete dir="${dist.home}"/>
  </target>



<!-- ==================== Compile Target ================================== -->

<!--

  The "compile" target transforms source files (from your "src" directory)
  into object files in the appropriate location in the build directory.
  This example assumes that you will be including your classes in an
  unpacked directory hierarchy under "/WEB-INF/classes".

  Rather than relying on the CLASSPATH environment variable, Ant includes
  features that makes it easy to dynamically construct the classpath you
  need for each compilation.  The example below constructs the compile
  classpath to include the servlet.jar file, as well as the other components
  that Tomcat makes available to web applications automatically, plus anything
  that you explicitly added.

  BE: moved classpath definition to here. Since the path now depends on files
  repositioned by the 'prepare' target, we cannot define the path until 
  prepare has been executed.
-->

  <target name="compile" depends="prepare"
   description="Compile Java sources">

    <!-- Compile Java classes as necessary -->
    <mkdir    dir="${build.home}/WEB-INF/classes"/>
    <javac srcdir="src"
          destdir="${build.home}/WEB-INF/classes"
           debug="${compile.debug}"
     deprecation="${compile.deprecation}"
        optimize="${compile.optimize}">
        <classpath id="compile.classpath">

          <!-- Include all JAR files from /WEB-INF/lib -->
          <pathelement location="${build.home}/WEB-INF/classes"/>
          <fileset dir="${build.home}/WEB-INF/lib">
            <include name="*.jar"/>
          </fileset>

          <!-- Include all elements that Tomcat exposes to applications -->
          <pathelement location="${catalina.home}/common/classes"/>
          <fileset dir="${catalina.home}/common/lib">
            <include name="*.jar"/>
          </fileset>
          <pathelement location="${catalina.home}/classes"/>
          <fileset dir="${catalina.home}/lib">
            <include name="*.jar"/>
          </fileset>
        </classpath>
    </javac>

    <!-- Copy associated resource files -->
    <!-- BE: removed 'library' fom path - it placed properties outside 
classpath -->
    <copy  todir="${build.home}/classes">
    <fileset dir="src" includes="**/*.properties"/>
    </copy>

  </target>



<!-- ==================== Deploy Target =================================== -->

<!--

  The "deploy" target copies the contents of the build directory into a
  location required by our servlet container, and picks up any external
  dependencies along the way.  AFter restarting the servlet container, you
  can now test your web application.

-->

  <target name="deploy" depends="compile"
   description="Deploy application to servlet container">

    <!-- Copy the contents of the build directory -->
    <mkdir     dir="${deploy.home}"/>
    <copy    todir="${deploy.home}">
      <fileset dir="${build.home}"/>
    </copy>

    <!-- BE: removed copying of libraries, now in 'prepare' target -->
  </target>



<!-- ==================== Dist Target ===================================== -->


<!--

  The "dist" target creates a binary distribution of your application
  in a directory structure ready to be archived in a tar.gz or zip file.
  Note that this target depends on two others:
  * "deploy" so that the entire web application (including external
    dependencies) will have been assembled
  * "javadoc" so that the application Javadocs will have been created

-->

  <target name="dist" depends="deploy,javadoc"
   description="Create binary distribution">

    <!-- Copy documentation subdirectory -->
    <copy    todir="${dist.home}/docs">
      <fileset dir="docs"/>
    </copy>

    <!-- Create application JAR file -->
    <jar jarfile="${dist.home}/${app.name}.war"
         basedir="${deploy.home}"/>

    <!-- Copy additional files to ${dist.home} as necessary -->

  </target>



<!-- ==================== Javadoc Target ================================== -->

<!--

  The "javadoc" target creates Javadoc API documentation for the Java
  classes included in your application.  Normally, this is only required
  when preparing a distribution release, but is available as a separate
  target in case the developer wants to create Javadocs independently.

  BE: added classpath from compilation, and made this task document
  all packages by default - more useful out of the box
-->

  <target name="javadoc" depends="compile"
   description="Create Javadoc API documentation">

    <mkdir          dir="${dist.home}/docs/api"/>
    <javadoc sourcepath="src"
                destdir="${dist.home}/docs/api"
           packagenames="*">
      <classpath refid="compile.classpath"/>
    </javadoc>

  </target>



<!-- ==================== Prepare Target ================================== -->

<!--

  The "prepare" target is used to create the "build" destination directory,
  and copy the static contents of your web application to it.  If you need
  to copy static files from external dependencies, you can customize the
  contents of this task.

  Normally, this task is executed indirectly when needed.

-->

  <target name="prepare">

    <!-- Create build directory and copy static content -->
    <mkdir  dir="${build.home}"/>
    <copy todir="${build.home}">
      <fileset dir="web"/>
    </copy>

    <!-- BE: moved copies here so theres no classpath duplication -->
    <!-- Copy external dependencies as required -->
    <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** -->
    <mkdir  dir="${build.home}/WEB-INF/lib"/>
<!--
    <copy todir="${build.home}/WEB-INF/lib" file="${foo.jar}"/>
-->

  </target>



</project>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to