简体   繁体   English

运行Apache Flink作业时链接失败

[英]Linkage failure when running Apache Flink jobs

I have a job developed in Flink 0.9 that is using the graph module (Gelly). 我在Flink 0.9中开发了一个使用图形模块(Gelly)的工作。 The job is running successfully within the IDE (Eclipse) but after exporting it to a JAR using maven (mvn clean install) it fails to execute on the local flink instance with the following error 作业在IDE(Eclipse)中成功运行,但在使用maven(mvn clean install)将其导出到JAR后,无法在本地flink实例上执行,并出现以下错误

"The program's entry point class 'myclass' could not be loaded due to a linkage failure" “由于链接失败,无法加载程序的入口点类'myclass'”

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

Any idea why is this happening and how to solve it? 知道为什么会发生这种情况以及如何解决它?

It looks like the code of flink-gelly did not end up in your jar file. 看起来flink-gelly的代码并没有最终出现在你的jar文件中。 The most obvious reason for this issue is the missing maven dependency in your project's pom file. 此问题最明显的原因是项目的pom文件中缺少maven依赖项。 But I assume the dependency is present, otherwise developing the job in the IDE would be impossible. 但我认为依赖存在,否则在IDE中开发工作是不可能的。

Most likely, the jar file has been created by the maven-jar-plugin , which is not including dependencies. 最有可能的是,jar文件是由maven-jar-plugin创建的,不包含依赖项。 Try adding the following fragment to your pom.xml : 尝试将以下片段添加到您的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>

Now, you can build the jar using mvn clean package -Pbuild-jar . 现在,您可以使用mvn clean package -Pbuild-jar构建mvn clean package -Pbuild-jar The jar file will now be located in the target/ directory. jar文件现在位于target/目录中。

You can manually check whether the jar (zip) file contains class files in /org/apache/flink/graph/ 您可以手动检查jar(zip)文件是否包含/org/apache/flink/graph/中的类文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM