Unable to compile and create .avro file from .avsc using Maven

I am new to Maven and have been studying tutorials and web pages for documentation on how to create .avro from a .avsc schema file. Based on documentation located on apache.maven.org. I have to add the following

<dependency> <groupId>org.apache.avro</groupId> <artifactId>avro</artifactId> <version>1.7.5</version> </dependency> <plugin> <groupId>org.apache.avro</groupId> <artifactId>avro-maven-plugin</artifactId> <version>1.7.5</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>schema</goal> </goals> <configuration> <sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory> <outputDirectory>${project.basedir}/src/main/java/</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> 

I added the same to my POM.xml file. I have 2 schema files (.avsc), and the following is the structure of my directory with contents

  • Projectdir
    • CSI
      • Main
        • Java
        • Avro
          • abc.avsc
        • Resources
    • test
  • pom.xml

My POM.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.training</groupId> <artifactId>TestAvro</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>TestAvro</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.basedir>/Users/vsank2/TestAvro</project.basedir> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.avro</groupId> <artifactId>avro</artifactId> <version>1.7.5</version> </dependency> <dependency> <groupId>org.apache.avro</groupId> <artifactId>avro-maven-plugin</artifactId> <version>1.7.5</version> </dependency> <dependency> <groupId>org.apache.avro</groupId> <artifactId>avro-compiler</artifactId> <version>1.7.5</version> </dependency> </dependencies> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.avro</groupId> <artifactId>avro-maven-plugin</artifactId> <version>1.7.5</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>schema</goal> </goals> <configuration> <sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory> <outputDirectory>${project.basedir}/src/main/java/</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugin</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </pluginManagement> </build> </project> 

I performed the following

mvn clean generate-sources, and I get the following output

 INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building TestAvro 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ TestAvro --- [INFO] Deleting /Users/vsank2/TestAvro/target [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.514s [INFO] Finished at: Mon Dec 23 16:08:51 PST 2013 [INFO] Final Memory: 2M/81M [INFO] ------------------------------------------------------------------------ 

Appreciate any help in this regard. thanks

+1
source share
1 answer

After much research, I found that the problem is completely related to my .avsc JSON problem. The "namespace" was completely wrong. As soon as I fixed it. The maven avro plugin created a java class from a schema.

+2
source

All Articles