Adding a Top-level Package

Adding a top-level package that you will compile as a separate operation and that a user will run separately doesn't happen very often.

There are several steps in making new top-level package that you can compile and run using package-specific Ant targets.

  • Add patternsets and paths for common, compile-time, and run-time classpaths to build-compile.xml
  • Add a compile target to build-compile.xml
  • Add the compile target to the next higher-level compile target in build-compile.xml
  • Add an Ant property for the jar or war file's name to build-compile.xml
  • Add a jar target to build-compile.xml
  • Add the new jar target as a dependency of the 'jars' target in build-compile.xml

Adding Patternsets and Classpaths to build-compile.xml

Each top-level package typically has three patternsets and two classpaths defined in build-compile.xml:

  • xxx.common.files - Files common to both compile-time and run-time.
  • xxx.compile.files - The common files plus files that are needed when compiling the package but not necessary when running it.
  • xxx.compile.classpath - xxx.compile.files expressed as a classpath.
  • xxx.run.files - The common files plus files that are needed when running the package but not necessary when compiling it.
  • xxx.run.classpath - xxx.run.files expressed as a classpath.

Example

<!-- Classpath used to compile the Bulk Loader -->
<patternset id="bulkLoader.common.files">
    <include name="${jaxr.provider.name}.jar"/>
    <include name="omar-common.jar"/>
    <include name="commons-logging.jar"/>
    <include name="ant.jar"/>
</patternset>

<patternset id="bulkLoader.compile.files">
    <patternset refid="jaxr.client.compile.files"/>
    <patternset refid="bulkLoader.common.files"/>
</patternset>
<path id="bulkLoader.compile.classpath">
    <fileset dir="${build.lib}">
        <patternset refid="bulkLoader.compile.files"/>
    </fileset>
</path>

<patternset id="bulkLoader.run.files">
    <patternset refid="jaxr.provider.run.files"/>
    <patternset refid="bulkLoader.common.files"/>
</patternset>
<path id="bulkLoader.run.classpath">
    <fileset dir="${build.lib}">
        <patternset refid="bulkLoader.run.files"/>
    </fileset>
</path>

Adding a Compile Target to build-compile.xml

Running this target compiles the package after all the target's dependencies have been satisfied.

Example

<target name="compile.bulkLoader" depends="jar.ebxml.provider" description="Compile the bulk loader">
    <javac fork="true" memoryMaximumSize="100m" debug="${compile.debug}" deprecation="${compile.deprecation}" destdir="${build.lib}/classes" optimize="${compile.optimize}" srcdir="${src.java}">        
        <classpath refid="bulkLoader.compile.classpath"/>
        <include name="org/freebxml/omar/client/bulkLoader/**"/>
    </javac>
</target>

Adding the Compile Target to the Next Higher-Level Compile Target in build-compile.xml

The next higher-level ".compile" target is probably compile.client, compile.common, or compile.server. If your package does not fit in any of those three categories, then it should probably be a dependency of compile.all.

Example

<target name="compile.client"
        depends="compile.ebxml.provider, compile.browser, compile.client.thin,
                 compile.bulkLoader, compile.ebxml.provider.tests"/>

Adding an Ant Property for the Jar or War File's Name

You should add this to the similar properties defined in build-compile.xml.

Example

<!-- Properties for *ar names -->
<property name="browser.name" value="registry-browser"/>
<property name="bulkLoader.name" value="bulk-loader"/>
<property name="jaxr.admin.name" value="jaxr-ebxml-admin"/>
<property name="jaxr.provider.name" value="jaxr-ebxml"/>
<property name="jaxr.test.name" value="jaxr-ebxml-test"/>

Adding a Jar Target

The created jar file should include a manifest that:

  • Identifies the package and attributes it to the project.
  • Specifies the package's main class as the jar's main class.
  • Specifies all other required jars in this jar's classpath.

Example

<target name="jar.bulkLoader" depends="compile.bulkLoader"
        description="create jar file containing only the Bulk Loader">
             
    <!-- Remove path prefixes from list of files and build a list for Class-Path -->
    <pathconvert property="bulkLoader.manifest.classpath"
                 setonempty="false"
                 dirsep="/" pathsep=" "
                 refid="bulkLoader.run.classpath">
        <map from="${build.lib}${file.separator}"
             to=""/>
    </pathconvert>

    <manifest file="${build.lib}/bulk-loader.manifest"
              mode="replace">
        
        <attribute name="Main-Class" 
                   value="org.freebxml.omar.client.bulkLoader.BulkLoaderTool"/>
        <attribute name="Class-Path" 
                   value="${bulkLoader.manifest.classpath}"/>
        <attribute name="Build-Time" 
                   value="${DSTAMP}${TSTAMP}"/>
        
        <section name="com/sun/xml/registry/client/bulkLoader">
            <attribute name="Specification-Title"
                       value="Bulk Loader"/>
            <attribute name="Specification-Version"
                       value="${dist.version}"/>
            <attribute name="Specification-Vendor"
                       value="freebxml"/>
            <attribute name="Implementation-Title"
                       value="Bulk Loader"/>
            <attribute name="Implementation-Version"
                       value="${dist.version}"/>
            <attribute name="Implementation-Vendor"
                       value="freebxml"/>
            <attribute name="Implementation-URL"
                       value="http://ebxmlrr.sourceforge.net/"/>
        </section>
        
    </manifest>
    
    <copy todir="${build.lib}/classes" file="conf/log4j.properties"/>
    
    <copy todir="${build.lib}/classes/META-INF"
          file="conf/mime.types"/>

    <jar manifest="${build.lib}/bulk-loader.manifest"
         jarfile="${build.lib}/${bulkLoader.name}.jar"
         basedir="${build.lib}/classes">
        <metainf dir="${build.lib}/classes/META-INF">
            <include name="mime.types"/>
        </metainf>
        <include name="org/freebxml/omar/client/bulkLoader/**"/>
        <include name="commons-logging.properties"/>
        <include name="log4j.properties"/>
    </jar>

</target>

Adding the New Jar Target to 'jars' Target

Once you do this, the new jar target will be compiled along with the other jars whenever the 'jars' target is run.

  • Identifies the package and attributes it to the project.
  • Specifies the package's main class as the jar's main class.
  • Specifies all other required jars in this jar's classpath.

Example

<target name="jars"
        depends="jar.ebxml.provider, jar.browser, jar.adminTool, jar.bulkLoader, jar.ebxml.provider.tests"
        description="Build jar files"/>