Search code examples
antbuildsubant

Ant failing with Content is not allowed in prolog


I am using subant and it is resulting into Content is not allowed in prolog problem.

    <subant target="main" genericantfile="build.xml">
        <fileset dir = "." />
    </subant>

Error:

The following error occurred while executing this line:
pattern.py:1: Content is not allowed in prolog.

Please note I have different files in those folders for example, python files.

When I use explicit listing using the filelist, all works fine.

<subant target="main" genericantfile="build.xml">                
      <filelist dir="." 
           files = "A/build.xml,
                    B/build.xml"
   />
</subant>

Solution

  • With subant you either specify genericantfile along with a dirset (to run the same build file many times, each time with a different basedir) or you omit genericantfile but supply a fileset or other resource collection of build files to run. You are mixing the two styles, and it looks like when you provide a fileset ant is ignoring the genericantfile attribute and treating each element of that fileset as a build file, attempting to parse each of the files as XML, and failing for those that are not XML (i.e. the python files).

    <subant target="main">
        <fileset dir = "." includes="**/build.xml" />
    </subant>
    

    would include only the real build files in the fileset.