1. Flink程序打Jar包

文章目录

步骤

  1. 用 maven 打 jar 包,需要在 pom.xml 文件中添加打包插件依赖
xml 复制代码
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                    <exclude>com.google.code.findbugs:jsr305</exclude>
                                    <exclude>org.slf4j:*</exclude>
                                    <exclude>log4j:*</exclude>
                                </excludes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <!-- Do not copy the signatures in the META-INF folder.
                                    Otherwise, this might cause SecurityExceptions when using the JAR. -->
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </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包中。
    因为:集群中,一般已经具备任务运行所需的所有依赖。
xml 复制代码
<!--  举例  -->
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java</artifactId>
    <version>${flink.version}</version>
    <!-- 打包时,不将该依赖放入jar包中 -->
    <scope>provided</scope>
</dependency>
  1. 打包前,需要先执行 clean,再执行 package
    如果第2步骤没有添加 scope,那么这两个Jar文件的大小是不一样的。

注意事项

  1. 当我们对导入的依赖添加 scope后,IDEA 的程序运行会报错:Caused by: java.lang.ClassNotFoundException xxx
    解决办法:

    缺点:每一次新建文件均需打勾勾。
    解决办法:
    添加 application template
相关推荐
tcoding1 小时前
《基于Apache Flink的流处理》笔记
笔记·flink·apache
linmoo19861 小时前
Flink 系列之二十二 - 高级概念 - 保存点
大数据·flink·savepoint·保存点
试剂界的爱马仕3 小时前
TCA 循环中间体如何改写肝损伤命运【AbMole】
大数据·人工智能·科技·机器学习·ai写作
Leo.yuan3 小时前
数据湖是什么?数据湖和数据仓库的区别是什么?
大数据·运维·数据仓库·人工智能·信息可视化
hao_wujing4 小时前
基于梯度的中毒攻击
大数据·人工智能
qq_4639448616 小时前
【Spark征服之路-2.2-安装部署Spark(二)】
大数据·分布式·spark
weixin_5051544617 小时前
数字孪生在建设智慧城市中可以起到哪些作用或帮助?
大数据·人工智能·智慧城市·数字孪生·数据可视化
打码人的日常分享17 小时前
智慧城市建设方案
大数据·架构·智慧城市·制造
阿里云大数据AI技术19 小时前
ES Serverless 8.17王牌发布:向量检索「火力全开」,智能扩缩「秒级响应」!
大数据·运维·serverless
Mikhail_G19 小时前
Python应用变量与数据类型
大数据·运维·开发语言·python·数据分析