Avro 简明教程
AVRO - Environment Setup
Apache 软件基金会提供带有各种版本的 Avro。你可以从 Apache 镜像中下载必需版本。让我们了解如何设置环境来使用 Avro:
Apache software foundation provides Avro with various releases. You can download the required release from Apache mirrors. Let us see, how to set up the environment to work with Avro −
Downloading Avro
要下载 Apache Avro,执行以下操作:
To download Apache Avro, proceed with the following −
-
Open the web page Apache.org. You will see the homepage of Apache Avro as shown below −

-
Click on project → releases. You will get a list of releases.
-
Select the latest release which leads you to a download link.
-
mirror.nexcess is one of the links where you can find the list of all libraries of different languages that Avro supports as shown below −

你可以选择和下载任何提供的语言的库。在本教程中,我们使用 Java。因此下载 jar 文件 avro-1.7.7.jar 和 avro-tools-1.7.7.jar 。
You can select and download the library for any of the languages provided. In this tutorial, we use Java. Hence download the jar files avro-1.7.7.jar and avro-tools-1.7.7.jar.
Avro with Eclipse
要在 Eclipse 环境中使用 Avro,你需要按照下面给出的步骤操作 −
To use Avro in Eclipse environment, you need to follow the steps given below −
-
Step 1. Open eclipse.
-
Step 2. Create a project.
-
Step 3. Right-click on the project name. You will get a shortcut menu.
-
Step 4. Click on Build Path. It leads you to another shortcut menu.
-
Step 5. Click on Configure Build Path… You can see Properties window of your project as shown below −

-
Step 6. Under libraries tab, click on ADD EXternal JARs… button.
-
Step 7. Select the jar file avro-1.77.jar you have downloaded.
-
Step 8. Click on OK.
Avro with Maven
你也可以使用 Maven 在你的项目中获取 Avro 库。下面给出了 Avro 的 pom.xml 文件。
You can also get the Avro library into your project using Maven. Given below is the pom.xml file for Avro.
<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>Test</groupId>
<artifactId>Test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-tools</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-beta9</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-beta9</version>
</dependency>
</dependencies>
</project>
Setting Classpath
要在 Linux 环境中使用 Avro,下载以下 jar 文件 −
To work with Avro in Linux environment, download the following jar files −
-
avro-1.77.jar
-
avro-tools-1.77.jar
-
log4j-api-2.0-beta9.jar
-
og4j-core-2.0.beta9.jar.
将这些文件复制到一个文件夹,并将类路径设置为 . /bashrc 文件中的文件夹,如下所示。
Copy these files into a folder and set the classpath to the folder, in the ./bashrc file as shown below.
#class path for Avro
export CLASSPATH=$CLASSPATH://home/Hadoop/Avro_Work/jars/*
