关于Apache maven shade plugin

pom中有很多依赖,但是如果你并不想把所有依赖都打包进入jar中,那么这个plugin就有使用用途了.

这个插件的用途就是 : maven工程指定依赖打成一个jar包

提取关键点:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <includes>
                                    <include>jd:jd-core</include>
                                    <include>org.javassist:javassist</include>
                                </includes>
                            </artifactSet>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.coderead.apm.ApmAgent</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

1.选择包含哪些依赖对应部分

							<artifactSet>
                                <includes>
                                    <include>jd:jd-core</include>
                                    <include>org.javassist:javassist</include>
                                </includes>
                            </artifactSet>

2.如果打成的shade的jar包也需要可运行,需要给它指定main入口, 对应部分

							<transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.coderead.apm.ApmAgent</mainClass>
                                </transformer>
                            </transformers>

参考链接:

https://blog.csdn.net/ww694303720/article/details/44810803
https://blog.csdn.net/qq_35799003/article/details/70226547
https://blog.csdn.net/u010666884/article/details/51846305

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Maven Shade PluginMaven 的一个插件,主要用于解决 Java 项目中的依赖问题。它的作用是将所有依赖库打包到一个可执行的 JAR 包中,以避免因为缺少依赖库而导致的运行错误。 Maven Shade Plugin 的主要功能包括: - 将所有的依赖库打包到一个 JAR 包中,避免运行时缺少依赖库; - 可以对依赖库进行重命名,避免不同依赖库之间的命名冲突; - 可以对资源文件进行过滤和重定向,以解决资源文件冲突或者版本不兼容的问题。 使用 Maven Shade Plugin 打包 JAR 包的步骤如下: 1. 在 pom.xml 文件中添加 Maven Shade Plugin 的依赖。 ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.0</version> </plugin> </plugins> </build> ``` 2. 配置 Maven Shade Plugin,包括输出文件名、重命名规则、过滤规则等。 ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <finalName>my-application</finalName> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> <relocations> <relocation> <pattern>org.apache.commons</pattern> <shadedPattern>myapp.org.apache.commons</shadedPattern> </relocation> </relocations> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 其中,`finalName` 指定输出文件名,`filters` 指定过滤规则,`relocations` 指定重命名规则。具体规则可以参考 Maven Shade Plugin 的官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值