maven-jar-plugin打包怎么把system依赖也加到MANIFEST.M文件中
时间: 2024-09-27 08:08:56 浏览: 46
Maven的`maven-jar-plugin`用于创建JAR包,如果你想在生成的JAR中包含系统的(通常是库或框架提供的)依赖,你需要配置`maven-shade-plugin`来合并这些依赖。这是因为默认情况下,`maven-jar-plugin`不会将系统依赖复制到目标JAR中。
首先,在你的`pom.xml`中添加`maven-shade-plugin`:
```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> <!-- 将项目打成fat-jar的目标 -->
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>your.MainClass</mainClass> <!-- 如果有主类指定它 -->
</transformer>
<!-- 这里可以设置是否包含system dependencies -->
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/*</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
在这个配置中,`ManifestResourceTransformer`用于添加MANIFEST.MF文件,而`AppendingTransformer`则会保留`META-INF/services`目录下的内容(如果有需要)。确保你的`<mainClass>`指向正确的入口点,如果依赖是Spring Boot应用,可能还需要调整一些其他选项。
如果你确实想包含所有的系统依赖,可能会遇到jar体积过大的问题,因为每个依赖都会包含其所有依赖的二进制内容。这通常在构建工具允许的情况下,仅对特定依赖进行阴影处理,而不是整个项目的依赖树。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)