We have been having problems deploying our webapp, and in the process of
troubleshooting this I've determined that I cannot understand what our Ant
buildfile is doing.

During deployment, the source code repository is pulled from GitHub into a
local repository ROOT/.  The source code contains the build file
`build.xml` in its root directory, `ROOT/build.xml`.

The webapp is made of multiple projects and the full `build.xml` is
probably too large to be useful to anyone trying to help.  To simplify it,
I've removed references to all but one project, labeled "project" and
provided it as an attachment.  Hopefully this is an adequate balance, but
I'm able to provide more or less information as needed.

The buildfile is invoked with the target `deploy-all-clean`, found at the
bottom of the buildfile.  I'll step through my understanding of how this is
implemented.

First, the `deploy-all-clean` target invokes the `distclean` target which
just does the `clean-jars`, `clean-classes`, and `clean-web` targets, which
collectively remove `.jar` and `.class` files from within `WEB-INF/` and
the JSP and other web files from the Tomcat webapp directory.

Second, `deploy-all-clean` invokes the `deploy-project` target, which is
nothing but an `<antcall>` to the `do-deploy-project` target.

The `do-deploy-project` target is where the main business happens.

First, it invokes a target `build-project` to do the building.  That target
makes sure the files common to all projects have already been built by
invoking the `build-common` target.  This is where my understanding first
breaks down.

1) Build common
This first creates the `common/build/` directory.  In practice, it will
already exist, so the next step is deleting any class files still there.
At this point, the structure of the directory where the build file is
executing looks something like this:

ROOT/
  |---project/
  |---common/
        |---build/
        |---resources/
        |     |---classes/
        |           |--- webapp.properties
        |---src/
              |---java/
                    |---<.java files>

The the target compiles everything from `common/src/java/` into the new
folder `common/build/`.

ROOT/
  |---project/
  |---common/
        |---build/
        |     |---< New .class files >    <-------
        |---resources/                           |
        |     |---classes/                       |
        |           |--- webapp.properties       |
        |---src/                                 |
              |---java/                          |
                    |---< .java files >   >-------

It then copies everything from the `common/` directory into the
`common/build/` directory, with special attention paid to the file
`common/resources/classes/webapp.properties`.  This should create the file
`common/build/resources/classes/webapp.properties`

ROOT/
  |---project/
  |---common/
        |---build/
        |     |---< New .class files >
        |     |---resources/
        |           |---classes/
        |                 |--- webapp.properties
        |---resources/
        |     |---classes/
        |           |--- webapp.properties
        |---src/
              |---java/
                    |---< .java files >

The first problem I have is that, after deployment, there is no
`common/build/resources/` folder they way I would expect from the `<copy>`
directive.  There *are* the .class files in namespaced folder hierarchies,
and there's nothing I can find in the rest of the build file that would
have deleted `common/build/resources/` at the end of deployment.

Can anyone identify an error in my understanding or in the construction of
this build file that would explain the lack of `common/build/resources/`?
I understand that the answer may lie outside of the information I've
provided; in that case my intent is to rule out an error in this
information before moving on to the next pile, so even a "No, this much
looks good" will be helpful.

I did not write this build file and I don't know who did.  I do know that
in its current form it has worked for innumerable successful deployments
over the past decade, including for multiple versions of Tomcat running on
multiple versions of Ubuntu.

Thank you for any help you can give.

Best,
Joel
<project name="sample">

    <property file="build.properties"/>

    <path id="cp-common">
        <fileset dir="common/lib">
            <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${container.libroot}/${container.libs}">
            <include name="**/*.jar"/>
        </fileset>
        <pathelement location="common/build"/>
        <pathelement location="common/resources/classes"/>
    </path>

    <path id="cp-project">
        <fileset dir="project">
            <include name="lib/**/*.jar"/>
        </fileset>
    </path>

    <target name="build-common">
        <mkdir dir="common/build"/>
        <delete quiet="true">
            <fileset dir="common/build"
                includes="**/*.class"/>.
        </delete>
        <javac srcdir="common/src/java" destdir="common/build" debug="true">
            <classpath refid="cp-common"/>
            <compilerarg value="-deprecation"/>
        </javac>
        <!-- the properties file -->
        <copy todir="common/build">
            <fileset dir="common" includes="webapp.properties"/>
        </copy>
    </target>

    <target name="clean-jars">
        <delete quiet="true">
            <fileset dir="tomcat10/webapps/app/WEB-INF/lib"
                includes="**/*.jar"/>
        </delete>
    </target>

    <target name="clean-classes">
        <delete quiet="true">
            <fileset dir="tomcat10/webapps/app/WEB-INF/classes"
                includes="**/*.class"/>
        </delete>
    </target>

    <target name="clean-web">
        <delete quiet="true">
            <fileset dir="tomcat10/webapps/webapp"
                includes="**/*.jsp, **/*.jspf, **/*.html, **/*.htm, **/*.js"/>
        </delete>
    </target>

    <target name="do-deploy-common" depends="build-common, clean-jars">
        <mkdir dir="tomcat10/webapps/app"/>
        <mkdir dir="tomcat10/webapps/app/capture" />
        <mkdir dir="tomcat10/webapps/app/capture/img" />
        <mkdir dir="tomcat10/webapps/app/WEB-INF"/>
        <mkdir dir="tomcat10/webapps/app/WEB-INF/classes"/>
        <mkdir dir="tomcat10/webapps/app/WEB-INF/lib"/>
        <mkdir dir="tomcat10/webapps/app/project"/>

        <copy todir="tomcat10/webapps/app/capture">
            <fileset dir="capture" includes="**/*" />
        </copy>        
        <copy todir="tomcat10/webapps/app/WEB-INF/lib">
            <fileset dir="common/lib" includes="**/*.jar"/>
        </copy>
        <copy todir="tomcat10/webapps/app/WEB-INF">
            <fileset dir="common/resources" includes="**/*"/>
        </copy>
        <copy todir="tomcat10/webapps/app/WEB-INF/classes">
            <fileset dir="common/build" includes="**/*" excludes="webapp.properties"/>
        </copy>
        <concat destfile="tomcat10/webapps/app/WEB-INF/webapp.properties" force="no">
            <fileset dir="common/build" includes="webapp.properties*"/>
        </concat>
        <copy todir="tomcat10/webapps/app/project">
            <fileset dir="common/src/jsp" includes="**/*.*"/>
        </copy>
    </target>


    <target name="build-project" depends="build-common" description="--> builds the project">
        <mkdir dir="project/build"/>
        <javac srcdir="project/src/java" destdir="project/build" debug="true">
            <include name="**/*.java"/>
            <classpath refid="cp-common"/>
            <classpath refid="cp-project"/>
            <compilerarg value="-deprecation"/>
        </javac>        
        <copy todir="common/build">
            <fileset dir="project" includes="webapp.properties.project"/>
        </copy>
    </target>

    <target name="deploy-project">
        <antcall target="do-deploy-project">
            <param name="webapp.name" value="project"/>
        </antcall>
    </target>

    <target name="do-deploy-project" depends="build-project, do-deploy-common">
        <mkdir dir="tomcat10/webapps/app/project"/>

        <copy todir="tomcat10/webapps/app/WEB-INF">
            <fileset dir="project" includes="lib/**/*.jar"/>
        </copy>
        <mkdir dir="project/resources"/>
        <copy todir="tomcat10/webapps/app/WEB-INF">
            <fileset dir="project/resources" includes="**/*"/>
        </copy>
        <copy todir="tomcat10/webapps/app/WEB-INF/classes">
            <fileset dir="project/build" includes="**/*.*"/>
        </copy>
        <copy todir="tomcat10/webapps/app/project" overwrite="true">
            <fileset dir="project/src/jsp" includes="**/*"/>
        </copy>
    </target>

    <target name="distclean" depends="clean-jars, clean-classes, clean-web">
    </target>

    <target name="deploy-all-clean" depends="distclean, deploy-project">
    </target>

</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to