如何通过maven将Hadoop添加到依赖项中



我正在尝试构建一个apache flink作业,该作业必须通过HDFS访问文件。它在本地运行良好,但当我将作业提交到flink集群时,我会得到错误:

Hadoop is not in the classpath/dependencies.

我正在使用Maven shade插件来构建我的job.jar。Flink集群没有Hadoop jar,所以我必须将它们全部添加到作业本身中。

在本地,我不得不在我的IDE设置中添加选项";使用"添加依赖项;提供";范围到类的路径使其工作,但我不知道如何使用maven做到这一点。

pom.xml


<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${dep.flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.11</artifactId>
<version>${dep.flink.version}</version>
<scope>provided</scope>
</dependency>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${plugin.maven-compiler.version}</version>
<configuration>
<source>${project.build.targetJdk}</source>
<target>${project.build.targetJdk}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${plugin.maven-shade.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>org.apache.commons.cli</pattern>
<shadedPattern>org.test.examples.thirdparty.commons_cli</shadedPattern>
</relocation>
</relocations>
<filters>
<!-- Filters out signed files to avoid SecurityException when integrating a signed jar in the resulting jar. -->
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

如果您在YARN上读取纱线部署。

确保已设置HADOOP_CLASSPATH环境变量(可以通过运行echo $HADOOP_CLASSPATH进行检查(。如果没有,请使用进行设置

export HADOOP_CLASSPATH=`hadoop classpath`

要添加maven依赖项,你可以转到你想要的maven repo搜索工件,选择你的版本,你会在第页上有一个依赖项代码,将其添加到你的.pom文件中:

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-hadoop-compatibility_2.11</artifactId>
<version>1.13.1</version>
<scope>test</scope>
</dependency>

您将其添加到标签<dependencies></dependencies>之间

相关内容

  • 没有找到相关文章

最新更新