非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
Transformer | Purpose |
---|---|
ApacheLicenseResourceTransformer | Prevents license duplication |
ApacheNoticeResourceTransformer | Prepares merged NOTICE |
AppendingTransformer | Adds content to a resource |
ComponentsXmlResourceTransformer | Aggregates Plexus components.xml |
DontIncludeResourceTransformer | Prevents inclusion of matching resources |
IncludeResourceTransformer | Adds files from the project |
ManifestResourceTransformer | Sets entries in the MANIFEST |
ServicesResourceTransformer | Merges META-INF/services resources |
XmlAppendingTransformer | Adds 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>