我的问题类似于Unable to compile and create .avro file from .avsc using Maven
我已经尝试了所有可能的事情,检查了maven项目100次,但仍然无法运行avro-maven插件来生成我的avsc文件的代码。
我已阅读以下帖子并遵循相同的规定,但没有成功 http://grepalex.com/2013/05/24/avro-maven/ https://github.com/phunt/avro-maven-plugin
我下载了上面的maven项目,结果也是如此。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Avro Maven Example 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ avro-maven ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ avro-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory F:\01_Work\FLink\avro-maven-master\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ avro-maven ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.932 s
[INFO] Finished at: 2015-08-10T19:16:44+05:30
[INFO] Final Memory: 6M/16M
[INFO] ------------------------------------------------------------------------
但没有生成代码。
我强烈认为Maven是我的致命敌人,我永远无法对apache项目做任何工作只是因为我无法让maven工作。也许我应该考虑回到更健全的C / C ++世界,它不需要互联网连接来编译我的来源。
答案 0 :(得分:2)
pom文件中的eclipse错误并不重要。确保.avsc文件具有名称空间值,即生成实际文件的位置。
{
"namespace": "com.hadoop.practice.avro",
"type": "record",
"name": "StringPair",
"doc": "A pair of strings",
"fields": [
{"name": "left", "type": "string"},
{"name": "right", "type": "string"}
]
}
StringPair.java在此命名空间定义的包
下生成答案 1 :(得分:2)
我发布了一个经过充分测试的简单演示,并且100%可以进行https://github.com/xmeng1/avro-maven-demo。 使用Avro生成代码有两个重要方面
mvn compile
或mvn package
时生成代码,可以将配置置于执行之下。 如果要在运行目标mvn avro:scheme
时生成代码,则需要将配置直接添加到插件中。 (该演示包括两种类型的配置){"namespace": "com.xx.xx.demo", "name": "Foo"}
,Foo.java
将在包com.xx.xx.demo
下创建答案 2 :(得分:0)
以下是我成功使用的示例POM文件。我的猜测是你的sourceDirectory& outputDirectory标签没有正确定义......
<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>com.example</groupId>
<artifactId>helloworld</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<!-- Keep Hadoop versions as properties to allow easy modification -->
<hadoop.version>2.6.0-cdh5.4.0</hadoop.version>
<avro.version>1.7.7</avro.version>
<mrunit.version>1.1.0</mrunit.version>
<!-- Maven properties for compilation -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>${avro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-tools</artifactId>
<version>${avro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.mrunit</groupId>
<artifactId>mrunit</artifactId>
<version>${mrunit.version}</version>
<classifier>hadoop2</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Set the Java target version to 1.7 -->
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</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-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
答案 3 :(得分:-1)
正如评论中所提到的,我在<pluginManagement>
上添加了一个<plugins>
标记,并为我解决了问题。我正在使用eclipse Mars。
示例:
<pluginManagement>
<plugins>
<plugin>....</plugin>
</plugins>
<pluginManagement>