flink idea 打包jar 并放到集群上运行

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集群未启动
 

猜你喜欢

转载自www.cnblogs.com/huangguoming/p/11769407.html