1. Flink程序打Jar包

文章目录

      • 步骤
      • 注意事项

步骤

  1. 用 maven 打 jar 包,需要在 pom.xml 文件中添加打包插件依赖
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-shade-pluginartifactId>
                <version>3.2.4version>
                <executions>
                    <execution>
                        <phase>packagephase>
                        <goals>
                            <goal>shadegoal>
                        goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                    <exclude>com.google.code.findbugs:jsr305exclude>
                                    <exclude>org.slf4j:*exclude>
                                    <exclude>log4j:*exclude>
                                excludes>
                            artifactSet>
                            <filters>
                                <filter>
                                    
                                    <artifact>*:*artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SFexclude>
                                        <exclude>META-INF/*.DSAexclude>
                                        <exclude>META-INF/*.RSAexclude>
                                    excludes>
                                filter>
                            filters>
                            <transformers combine.children="append">
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer">
                                transformer>
                            transformers>
                        configuration>
                    execution>
                executions>
            plugin>
        plugins>
    build>
  1. 建议:对导入的依赖添加 scope
    作用:打包时,不将该依赖放入jar包中。
    因为:集群中,一般已经具备任务运行所需的所有依赖。

<dependency>
    <groupId>org.apache.flinkgroupId>
    <artifactId>flink-streaming-javaartifactId>
    <version>${flink.version}version>
    
    <scope>providedscope>
dependency>
  1. 打包前,需要先执行 clean,再执行 package
    如果第2步骤没有添加 scope,那么这两个Jar文件的大小是不一样的。
    1. Flink程序打Jar包_第1张图片

注意事项

  1. 当我们对导入的依赖添加 scope后,IDEA 的程序运行会报错:Caused by: java.lang.ClassNotFoundException xxx
    解决办法:
    1. Flink程序打Jar包_第2张图片
    缺点:每一次新建文件均需打勾勾。
    解决办法:
    添加 application template
    1. Flink程序打Jar包_第3张图片

你可能感兴趣的:(#,Flink,flink,jar,大数据)