我在Flink 0.9中开发了一个使用图形模块(Gelly)的工作。作业在IDE(Eclipse)中成功运行,但在使用maven(mvn clean install)将其导出到JAR后,无法在本地flink实例上执行,并出现以下错误
“由于链接失败,无法加载程序的入口点类'myclass'”
java.lang.NoClassDefFoundError: org/apache/flink/graph/GraphAlgorithm
知道为什么会发生这种情况以及如何解决它?
答案 0 :(得分:4)
看起来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/