Search code examples
antbuild.xml

jar files included in build.xml is not taken in the classpath in the declared order


This is my build.xml file. I have included the jar files in the specific order which I require (This is important. If not I will get package is sealed exception). But the classpath I get is:

[echo] Classpath is C:\Users\aswathy_krishnan\eclipse-workspace\MerckDemo\lib\iwats-scripting-library-v1.9.jar;C:\Users\aswathy_krishnan\eclipse-workspace\MerckDemo\lib\jcommander-1.27.jar;C:\Users\aswathy_krishnan\eclipse-workspace\MerckDemo\lib\json-20160810.jar;C:\Users\aswathy_krishnan\eclipse-workspace\MerckDemo\lib\tessract-wrapper.jar;C:\Users\aswathy_krishnan\eclipse-workspace\MerckDemo\lib\testng-6.11.jar

What am I doing wrong? How can I make sure my tesseract wrapper is always the first jar to be included? I am a beginner in ANT.

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <project basedir="." default="main" name="MerckDemo">
        <property environment="env" />
        <property name="debuglevel" value="source,lines,vars" />
        <property name="target" value="1.8" />
        <property name="source" value="1.8" />
        <property name="src.dir" location="src" />
        <property name="build.dir" location="bin" />
        <property name="dist.dir" location="dist" />
        <property name="resources" location="resources" />
        <property name="jardest" location="jardest" />
        <property name="docs.dir" location="docs" />
        <property name="lib" location="lib" />


        <path id="build.classpath">
            <fileset dir="${lib}">
                <include name="tessract-wrapper.jar" />
                <include name="testng-6.11.jar" />
                <include name="iwats-scripting-library-v1.9.jar" />
                <include name="json-20160810.jar" />
                <include name="jcommander-1.27.jar" />
            </fileset>
        </path>

        <pathconvert property="classpathProp" refid="build.classpath" />
        <echo>Classpath is ${classpathProp}</echo>

        <target name="clean">
            <delete dir="${build.dir}" />
            <delete dir="${dist.dir}" />
            <delete dir="${docs.dir}" />
        </target>

        <target name="init">
            <mkdir dir="bin" />
            <mkdir dir="dist" />
            <mkdir dir="docs" />

        </target>
        <target name="compile" depends="clean,init">
            <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" includeantruntime="false">
            </javac>
        </target>

        <target name="docs">
            <javadoc sourcepath="${src.dir}" destdir="${docs.dir}">
                <fileset dir="${src.dir}">
                    <include name="**" />
                </fileset>
            </javadoc>
        </target>
        <target name="setproperties">
            <copy file="testproperties.templete" tofile="test.properties" overwrite="true">
                <filterset begintoken="@" endtoken="@">
                    <filter token="application_type" value="${application_type}" />
                    <filter token="remote_host" value="${remote_host}" />
                    <filter token="remote_port" value="${remote_port}" />
                    <filter token="testng_group" value="${testng_group}" />
                    <filter token="testng_package" value="${testng_package}" />
                </filterset>
            </copy>

        </target>

        <target depends="compile,setproperties" name="main">
            <java classname="merck.trigger.Trigger" classpath="${build.dir}" classpathref="build.classpath" fork="true">

            </java>
        </target>
        <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects" />
    </project>

I tried running the test via testNG and it works fine.This is because I gave priority to my tesseract jar in order and export tab of buildpath. Please help.


Solution

  • fileset does not result in an ordered collection. To order the elements in your classpath definition, you should use multiple <pathelement ...> instead:

    <path id="build.classpath">
        <pathelement location="${lib}/tessract-wrapper.jar"/>
        <pathelement location="${lib}/testng-6.11.jar"/>
        <pathelement location="${lib}/iwats-scripting-library-v1.9.jar"/>
        <pathelement location="${lib}/json-20160810.jar"/>
        <pathelement location="${lib}/jcommander-1.27.jar"/>
    </path>