【问题标题】:Linkage failure when running Apache Flink jobs运行 Apache Flink 作业时链接失败
【发布时间】:2015-05-07 13:28:35
【问题描述】:

我在 Flink 0.9 中开发了一个使用图形模块(Gelly)的工作。该作业在 IDE (Eclipse) 中成功运行,但在使用 maven (mvn clean install) 将其导出到 JAR 后,它无法在本地 flink 实例上执行,并出现以下错误

“由于链接失败,无法加载程序的入口点类'myclass'”

java.lang.NoClassDefFoundError: org/apache/flink/graph/GraphAlgorithm

知道为什么会发生这种情况以及如何解决吗?

【问题讨论】:

  • 您是否使用 Flink 的 quickstart.sh (=Maven archetype) 创建了项目 pom?你的 pom 中有 flink-gelly 作为依赖项吗?

标签: maven apache-flink gelly


【解决方案1】:

看起来flink-gelly 的代码没有出现在您的 jar 文件中。 此问题最明显的原因是项目的 pom 文件中缺少 maven 依赖项。但我假设存在依赖关系,否则无法在 IDE 中开发作业。

很可能,jar 文件是由maven-jar-plugin 创建的,它不包括依赖项。 尝试将以下片段添加到您的 pom.xml

    <build>
    <plugins>
        <!-- We use the maven-shade plugin to create a fat jar that contains all dependencies
        except flink and it's transitive dependencies. The resulting fat-jar can be executed
        on a cluster. Change the value of Program-Class if your program entry point changes. -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <!-- Run shade goal on package phase -->
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>org.apache.flink:*</artifact>
                                <excludes>
                                    <exclude>org/apache/flink/shaded/**</exclude>
                                    <exclude>web-docs/**</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <!-- add Main-Class to manifest file -->
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>YOURMAINCLASS</mainClass>
                            </transformer>
                        </transformers>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>
<profiles>
    <profile>
        <!-- A profile that does everyting correctly:
        We set the Flink dependencies to provided -->
        <id>build-jar</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
                <groupId>org.apache.flink</groupId>
                <artifactId>flink-java</artifactId>
                <version>0.9-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.flink</groupId>
                <artifactId>flink-streaming-core</artifactId>
                <version>0.9-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.flink</groupId>
                <artifactId>flink-clients</artifactId>
                <version>0.9-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </profile>
</profiles>

现在,您可以使用 mvn clean package -Pbuild-jar 构建 jar。 jar 文件现在将位于target/ 目录中。

您可以手动检查jar(zip)文件是否包含/org/apache/flink/graph/中的类文件

【讨论】:

  • 确实如此。我不得不从 pom.xml 中删除 maven-jar-plugin 并在修改 Flink 版本后添加上面的 sn-p。我现在可以在本地实例上成功运行了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-30
  • 2020-09-21
  • 1970-01-01
  • 2018-11-24
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
相关资源
最近更新 更多