Flink的Quickstart并没有创造出适当的胖罐

时间:2016-03-03 16:14:44

标签: maven apache-flink

我绝对不是mvn的专家,但经过2天的黑客攻击,我只是放弃了。

我的工作流程:

1.     
     mvn archetype:generate                             
    -DarchetypeGroupId=org.apache.flink            
    -DarchetypeArtifactId=flink-quickstart-scala   
    -DarchetypeVersion=0.10.1                       
    -DgroupId=org.apache.flink.quickstart          
    -DartifactId=flink-scala-project               
    -Dversion=0.1                                  
    -Dpackage=org.apache.flink.quickstart          
    -DinteractiveMode=false    

2.    
   cd flink-scala-project 

3.     
  mvn clean package

这是一个构建log: https://gist.github.com/zavalit/1e78478ebdda827f3454,当我运行

`java -jar target/flink-scala-project-0.1.jar`

我得到了

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/scala/ExecutionEnvironment$
    at org.apache.flink.quickstart.Job$.main(Job.scala:41)
    at org.apache.flink.quickstart.Job.main(Job.scala)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.scala.ExecutionEnvironment$
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 2 more

2 个答案:

答案 0 :(得分:5)

您正在构建的胖罐不应该在群集环境之外运行。因此,在群集环境中运行的所有Flink相关依赖项都将从胖jar中排除。

您通常使用生成的胖jar执行的操作是通过<div class="tabs"> <ul> <li>tab one</li> <li>tab two</li> <li>tab three</li> </ul> </div> <div class="content"> <p>content content content content content content content content content content content content content content content content content content content content content content content content content </p> </div>将其提交到本地或远程群集。为了快速启动本地群集,您可以运行bin/flink run -c org.example.MyJob myFatJar.jar。这将启动您可以提交作业jar的本地群集。

答案 1 :(得分:1)

默认情况下,flink库不包含在fat jar中,因为它将在运行时由flink cluster提供。要解决此问题,请将scope中的pom.xml依赖项从provided更改为compile

<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-java</artifactId>
    <version>${flink.version}</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
    <version>${flink.version}</version>
    <scope>compile</scope>
</dependency>

link:Maven Doc