Maven项目代码和jar包分开打包

引言

代码包和依赖包分开打包这样的好处是:如果只修改了逻辑代码,没有修改依赖,就只需要更新代码包即可。
在pom.xml中中做如下修改:

步骤1

<project>节点中修改

1
<packaging>war</packaging>改成<packaging>jar</packaging>

步骤2

<build>下<plugins>节点中注释掉

1
2
3
4
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

步骤3

<build>下<plugins>节点中添加如下配置:

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
28
29
30
31
32
33
34
35
36
37
38
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-installed</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
</artifactItem>
</artifactItems>
<outputDirectory>target/lib</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-lib</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>compile</includeScope>
</configuration>
</execution>
</executions>
</plugin>

效果图


参考: https://www.cnblogs.com/lishan1/p/10317488.html
------------- 本文结束  感谢您的阅读 -------------
评论