How to generate Avro .avsc files in ANT build

568 views Asked by At

I need to generate files from .avsc file (avro) in ANT build. I'm not sure what plugin should I use for this. I tried with xjc.XJC2Task for generating the files but it seem to not work. Can some one suggest what plugin / class should I use to generate the files from avro schema in ANT ?

Tried with xjc:

    <target name="generate" description="generate">
        <mkdir dir="generated" />
        <taskdef name="xjc" classname="com.sun.tools.xjc.XJC2Task" classpathref="classpath"/>
        <xjc destdir="generated">
            <schema dir="setup/kafka" includes="*.avsc" />
        </xjc>
    </target>

Error:

    generate:
          [xjc] Consider using <depends>/<produces> so that XJC won't do unnecessary compilation
          [xjc] Compiling file:/D:/2019/My-workspace/my-project/setup/kafka/Sample.avsc
          [xjc] [ERROR] Content is not allowed in prolog.
          [xjc]   line 1 of file:/D:/2019/My-workspace/my-project/setup/kafka/Sample.avsc
          [xjc] failure in the XJC task. Use the Ant -verbose switch for more details
1

There are 1 answers

0
Heisenberg On

Used java jar command to compile the avro-tools jar . it worked.

 <target name="run-avro">
    <java jar="lib/avro-tools-1.10.1.jar" fork="true">
        <arg line="compile schema"/>
        <arg file="avrolocation/Sample.avsc"/>
        <arg file="generated/"/>
    </java>
    </target>