alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (manifestclasspath.xml)

This example Ant source code file (manifestclasspath.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

add, add, all, all, beta, beta, class-path, jaxb, jaxb, main-class

The manifestclasspath.xml source code

<?xml version="1.0"?>

<project name="manifestclasspath" default="tearDown">
  <!-- hebrew -->
  <property name="jom" value="םוי"/>
  <!-- german -->
  <property name="aent" value="ãnt"/> 
  <target name="setUp">
    <property name="tmp" location="${basedir}/${ant.project.name}.tmp" />
    <mkdir dir="${tmp}" />
  </target>

  <target name="fullSetUp" depends="setUp">
    <mkdir dir="${tmp}/lib" />
    <touch file="${tmp}/lib/acme-core.jar" />
    <touch file="${tmp}/lib/acme-pres.jar" />

    <mkdir dir="${tmp}/classes/dsp-core/com/lgc/infra/core" />
    <mkdir dir="${tmp}/classes/dsp-pres/com/lgc/infra/pres" />
    <mkdir dir="${tmp}/classes/dsp-void" />
    <mkdir dir="${tmp}/generated/dsp-core/com/lgc/infra/core/generated" />
    <mkdir dir="${tmp}/generated/dsp-pres" />
    <mkdir dir="${tmp}/generated/dsp-void" />
    <mkdir dir="${tmp}/resources/dsp-core/com/lgc/infra/core" />
    <mkdir dir="${tmp}/resources/dsp-pres/com/lgc/infra/pres" />
    <mkdir dir="${tmp}/resources/dsp-void" />
  </target>

  <target name="tearDown">
    <delete dir="${tmp}" />
  </target>

  <target name="test-bad-directory">
    <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/classpath.jar">
      <classpath />
    </manifestclasspath>
  </target>

  <target name="test-bad-no-property" depends="setUp">
    <manifestclasspath jarfile="${tmp}/classpath.jar">
      <classpath />
    </manifestclasspath>
  </target>

  <target name="test-bad-property-exists" depends="setUp">
    <property name="jar.classpath" value="exists" />
    <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/classpath.jar">
      <classpath />
    </manifestclasspath>
  </target>

  <target name="test-bad-no-jarfile" depends="setUp">
    <manifestclasspath property="jar.classpath">
      <classpath />
    </manifestclasspath>
  </target>

  <target name="test-bad-no-classpath" depends="setUp">
    <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/classpath.jar" />
  </target>

  <target name="test-pseudo-tahoe-refid" depends="fullSetUp">
    <path id="classpath">
      <!-- All the classes/ directories -->
      <dirset dir="${tmp}/classes"   includes="dsp-*" />

      <!-- All the JAXB generated/ directories -->
      <dirset dir="${tmp}/generated" includes="dsp-*">
        <!-- Add only non-empty directories to the classpath -->
        <present targetdir="${tmp}/generated" present="both">
          <mapper type="regexp" from="(.*)" to="\1/com" />
        </present>
      </dirset>

      <!-- All the resources/ directories -->
      <dirset dir="${tmp}/resources" includes="dsp-*">
        <!-- Add only non-empty directories to the classpath -->
        <present targetdir="${tmp}/resources" present="both">
          <mapper type="regexp" from="(.*)" to="\1/com" />
        </present>
      </dirset>
    </path>

    <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/classpath.jar">
      <classpath refid="classpath" />
    </manifestclasspath>
  </target>

  <target name="test-pseudo-tahoe-nested" depends="fullSetUp">
    <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/classpath.jar">
      <classpath>
        <!-- All the classes/ directories -->
        <dirset dir="${tmp}/classes"   includes="dsp-*" />

        <!-- All the JAXB generated/ directories -->
        <dirset dir="${tmp}/generated" includes="dsp-*">
          <!-- Add only non-empty directories to the classpath -->
          <present targetdir="${tmp}/generated" present="both">
            <mapper type="regexp" from="(.*)" to="\1/com" />
          </present>
        </dirset>

        <!-- All the resources/ directories -->
        <dirset dir="${tmp}/resources" includes="dsp-*">
          <!-- Add only non-empty directories to the classpath -->
          <present targetdir="${tmp}/resources" present="both">
            <mapper type="regexp" from="(.*)" to="\1/com" />
          </present>
        </dirset>
      </classpath>
    </manifestclasspath>
  </target>

  <target name="test-parent-level1" depends="fullSetUp">
    <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/classes/classpath.jar">
      <classpath>
        <dirset dir="${tmp}/classes"   includes="dsp-*" />
        <dirset dir="${tmp}/generated" includes="dsp-*" />
        <dirset dir="${tmp}/resources" includes="dsp-*" />
      </classpath>
    </manifestclasspath>
  </target>

  <target name="test-parent-level2" depends="fullSetUp">
    <mkdir dir="${tmp}/classes/level2" />
    <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/classes/level2/classpath.jar">
      <classpath>
        <dirset dir="${tmp}/classes"   includes="dsp-*" />
        <dirset dir="${tmp}/generated" includes="dsp-*" />
        <dirset dir="${tmp}/resources" includes="dsp-*" />
      </classpath>
    </manifestclasspath>
  </target>

  <target name="test-parent-level2-too-deep" depends="fullSetUp">
    <mkdir dir="${tmp}/classes/level2" />
    <manifestclasspath property="jar.classpath" maxParentLevels="1"
                       jarfile="${tmp}/classes/level2/classpath.jar">
      <classpath>
        <dirset dir="${tmp}/classes"   includes="dsp-*" />
        <dirset dir="${tmp}/generated" includes="dsp-*" />
        <dirset dir="${tmp}/resources" includes="dsp-*" />
      </classpath>
    </manifestclasspath>
  </target>

  <target name="test-parent-level2-with-jars" depends="fullSetUp">
    <mkdir dir="${tmp}/classes/level2" />
    <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/classes/level2/classpath.jar">
      <classpath>
        <fileset dir="${tmp}/lib" includes="*.jar" />
        <dirset dir="${tmp}/classes"   includes="dsp-*" />
        <dirset dir="${tmp}/generated" includes="dsp-*" />
        <dirset dir="${tmp}/resources" includes="dsp-*" />
      </classpath>
    </manifestclasspath>
  </target>

  <target name="international-german" depends="setUp">
      <antcall target="run-two-jars">
          <param name="ext.dir" value="${aent}"/>
      </antcall>
  </target>
  <target name="international-hebrew" depends="setUp">
      <antcall target="run-two-jars">
          <param name="ext.dir" value="${jom}"/>
      </antcall>
  </target>
  <target name="run-two-jars">
     <mkdir dir="${tmp}/${ext.dir}"/>
      <javac srcdir="manifestclasspath" destdir="${tmp}" />
       <jar destfile="${tmp}/${ext.dir}/alpha.jar">
          <fileset dir="${tmp}">
              <include name="Alpha.class"/>
          </fileset>
       </jar>
        <manifestclasspath property="jar.classpath"
                       jarfile="${tmp}/beta.jar">
        <classpath>
           <pathelement location="${tmp}/beta.jar"/>
           <pathelement location="${tmp}/${ext.dir}/alpha.jar"/>
        </classpath>
       </manifestclasspath>
      <jar destfile="${tmp}/beta.jar" >
          <fileset dir="${tmp}">
              <include name="Beta.class"/>
          </fileset>
          <manifest>
             <attribute name="Main-Class" value="Beta"/>
             <attribute name="Class-Path" value="${jar.classpath}"/>
          </manifest>
      </jar>
      <java fork="true" jar="${tmp}/beta.jar"/>
    </target>
</project>

Other Ant examples (source code examples)

Here is a short list of links related to this Ant manifestclasspath.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.