flink idea 打包jar 並放到集群上運行
在開始之前注意前提,當前項目的scala的版本要和集群上的scala一致
我已經創建好一個wordCount的flink項目
注意項目的pom文件給這些依賴加上<scope>provided</scope>(表示執行和打包都不用此依賴,只有編譯時用)不進行這些依賴的打包,因為這些依賴集群的環境都有了,不排除的話,會導致jar包很大,同時還容易很集群的依賴沖突
方法一
在pom文件里加入插件配置
<build>
<plugins>
<!-- 編譯插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- scala編譯插件 -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<configuration>
<scalaCompatVersion>2.11</scalaCompatVersion>
<scalaVersion>2.11.12</scalaVersion>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>compile-scala</id>
<phase>compile</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile-scala</id>
<phase>test-compile</phase>
<goals>
<goal>add-source</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 打jar包插件(會包含所有依賴) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- 可以設置jar包的入口類(可選) -->
<mainClass>com.hw.WorldCount</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
這里的入口類要修改成你main函數在的類
在命令行輸入:mvn clean package -DskipTests
得到
選擇with-dependencies的jar發布到集群上
方法二
先打開Project Structure
選擇好項目的入口類
理由同上
然后點apply ,ok
開始build
打包完成
發送到集群上
standalone集群上運行
提交任務
如果是在yarn集群上,則要指定好相應的配置
./bin/flink run -m yarn-cluster -yn 2 -yjm 1024 -ytm 1024 ./examples/batch/WordCount.jar
到集群web8081端口查看
如果遇到8081端口無法訪問,很可能是防火牆沒關或者flink集群未啟動
