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
相关推荐
九河云42 分钟前
海上风电“AI偏航对风”:把发电量提升2.1%,单台年增30万度
大数据·人工智能·数字化转型
一心赚狗粮的宇叔1 小时前
中级软件开发工程师2025年度总结
java·大数据·oracle·c#
盛世宏博北京1 小时前
云边协同・跨系统联动:智慧档案馆建设与功能落地
大数据·人工智能
DX_水位流量监测4 小时前
大坝安全监测之渗流渗压位移监测设备技术解析
大数据·运维·服务器·网络·人工智能·安全
Jackeyzhe4 小时前
Flink源码阅读:Task数据交互
flink
面向Google编程4 小时前
Flink源码阅读:Netty通信
大数据·flink
九河云5 小时前
从“被动适配”到“主动重构”:企业数字化转型的底层逻辑
大数据·人工智能·安全·重构·数字化转型
因我你好久不见6 小时前
Windows部署springboot jar支持开机自启动
windows·spring boot·jar
培培说证6 小时前
2026 中专大数据技术专业考证书门槛低的有哪些?
大数据
小北方城市网7 小时前
第1课:架构设计核心认知|从0建立架构思维(架构系列入门课)
大数据·网络·数据结构·python·架构·数据库架构