maven打包普通可执行jar

本文介绍如何使用Apache Maven Shade Plugin将Java项目打包成包含所有依赖的单个可执行jar文件。通过配置不同的资源转换器(Resource Transformers),如ManifestResourceTransformer来定制打包过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

非spring boot的普通Java可执行jar,使用maven打包,参考Apache Maven Shade Plugin;

Apache Maven Shade Plugin

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

uber	英[ˈuːbə(r)]   美[ˈuːbər]
adj.	超级; 极其;

shade在文中就给与了解释:)

Usage Creating a Shaded JAR;,中讲述了几个Resource Transformers

TransformerPurpose
ApacheLicenseResourceTransformerPrevents license duplication
ApacheNoticeResourceTransformerPrepares merged NOTICE
AppendingTransformerAdds content to a resource
ComponentsXmlResourceTransformerAggregates Plexus components.xml
DontIncludeResourceTransformerPrevents inclusion of matching resources
IncludeResourceTransformerAdds files from the project
ManifestResourceTransformerSets entries in the MANIFEST
ServicesResourceTransformerMerges META-INF/services resources
XmlAppendingTransformerAdds XML content to an XML resource

ManifestResourceTransformer作用于MANIFEST.MF文件,具体举例看这里

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <configuration>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>Test</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

spring boot打包jar最基本插件

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值