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
相关推荐
洋洋不叫杨杨1 小时前
Codex 实战:用 AI 写运维脚本
大数据·python
Regentsoft丽晶软件2 小时前
即时零售退货的库存归属、质检标准和退款时效,系统如何做到自动闭环
大数据·经验分享·数据库架构
动恰客流统计2 小时前
线下零售数字化浪潮下,客流统计的3个核心发展趋势
大数据·前端·人工智能
adinnet20262 小时前
Neo4j 凭什么叫原生图数据库?Cypher 查询能做什么
大数据·人工智能
见闻小天地3 小时前
脱硫脱硝塔选变频器避坑指南:四方DL500变频器使用体验分享
大数据·运维·人工智能·业界资讯
算了吧95693 小时前
从RAG机制到品牌AI可见度:2026年GEO技术架构的演进与行业实践观察
大数据·科技
精益数智工坊4 小时前
元数据管理怎么落地?元数据管理实施路径有哪些?
大数据·人工智能·数据挖掘·数据可视化
huashengzsj4 小时前
渠道数据采集平台怎么选?2026年专业的渠道数据采集平台推荐
大数据
IT_Octopus5 小时前
从一个应用开发者的角度,搞懂大数据查询的完整链路
java·大数据·数据库
安全指北针5 小时前
数据安全产品 POC 验证怎么做?一套可落地的评估方法
大数据·安全