簡體   English   中英

運行Apache Flink作業時鏈接失敗

[英]Linkage failure when running Apache Flink jobs

我在Flink 0.9中開發了一個使用圖形模塊(Gelly)的工作。 作業在IDE(Eclipse)中成功運行,但在使用maven(mvn clean install)將其導出到JAR后,無法在本地flink實例上執行,並出現以下錯誤

“由於鏈接失敗,無法加載程序的入口點類'myclass'”

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

知道為什么會發生這種情況以及如何解決它?

看起來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構建mvn clean package -Pbuild-jar jar文件現在位於target/目錄中。

您可以手動檢查jar(zip)文件是否包含/org/apache/flink/graph/中的類文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM