1
2
3
4
5
6
7
8
9
10
11
12
13
title: SpringBoot使用外部目录放jar包
author: maxzhao

tags:
- Java
- Maven

categories:
- SpringBoot
- Maven

abbrlink: 31330vxcv
date: 2024-06-16 00:00:00

SpringBoot使用外部目录放jar包

配置 pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.xxxxApplication</mainClass>
<layout>ZIP</layout>
<includeSystemScope>true</includeSystemScope>
<fork>true</fork>
<includes>
<include>
<groupId>no</groupId>
<artifactId>no</artifactId>
</include>
</includes>
</configuration>
</plugin>

这里配置所有的jar都不要。

也可以单独去除某些依赖

1
2
3
4
5
6
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>

配合 maven-dependency-plugin 输出jar包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs/</outputDirectory>
<includeScope>runtime</includeScope>
<!-- 以下排除 test 范围的依赖 -->
<excludeScope>test</excludeScope>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<!--包含的jar,多个用英文逗号分隔-->
<includeArtifactIds>bcprov-jdk15on</includeArtifactIds>
<!--不包含的jar,多个用英文逗号分隔-->
<excludeArtifactIds>bcprov-jdk15on</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>

本文地址: https://github.com/maxzhao-it/blog/post/0/