问题描述
我是Maven的新手,一直在教程和Web上寻找有关如何从模式文件.avsc构建.avro的文档.基于apache.maven.org站点上的文档.我必须添加以下
I'm new to Maven and have been looking at tutorials and web for documentation on how to build a .avro from a schema file .avsc. Based on the documentation that on the apache.maven.org site. 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>
我已将其添加到我的POM.xml文件中.我有2个架构文件(.avsc),以下是我的目录结构,其中包含内容
I've added the same into my POM.xml file. I have 2 schema files (.avsc) and following is my directory structure with contents
- ProjectDir
- src
- 主要
- java
- avrò
- abc.avsc
- ProjectDir
- src
- main
- java
- avrò
- abc.avsc
我的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>
我执行了以下
mvn clean generate-sources,我得到以下输出
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. thank you
推荐答案
经过大量研究,我发现问题完全出在我的.avsc JSON问题上. 命名空间"是完全错误的.我一修好就可以了. Maven Avro插件从该架构创建了Java类.
After a lot of research I found that the problem was completely with my .avsc JSON problem. The "namespace" was totally wrong. As soon as I fixed it. The maven avro plugin created the java class from the schema.
这篇关于无法使用Maven从.avsc编译和创建.avro文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- main
- src
- 主要
- src