运行apache flink作业时链接失败

atmip9wb  于 2021-06-24  发布在  Flink
关注(0)|答案(1)|浏览(484)

我在flink0.9中开发了一个使用graph模块(gelly)的作业。该作业在ide(eclipse)中成功运行,但是在使用maven(mvn clean install)将其导出到jar之后,它无法在本地flink示例上执行,错误如下
“由于链接失败,无法加载程序的入口点类‘myclass’。”

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

你知道为什么会这样,怎么解决吗?

jyztefdp

jyztefdp1#

它看起来像是 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文件现在将位于 target/ 目录。
您可以手动检查jar(zip)文件中是否包含类文件 /org/apache/flink/graph/

相关问题