• 案例:如下是某一个项目的项目架构SpringBoot项目引用离线的包打包正确姿势_spring
  • 使用​​idea​​​的maven Helper打包编译的话,压根就没什么难度一键即可,但是如果使用的​​CLI​​(命令行)打包编译就不会这么智能了
  • 使用​​CLI​​编译步骤如下:
  1. 在pom.xml中添加引用包的依赖位置。
<dependency>
<groupId>icu.smile</groupId>
<artifactId>MagicMQ</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/MagicMQ-1.0-SNAPSHOT.jar</systemPath>
</dependency>

注意⚠️ :这里因为是对于项目的来说是系统级别的调用所以scope为system,系统路径为系统全路径${project.basedir}标识取整个项目的绝对路径。

  1. 加入构建插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>

注意⚠️ :主要是加入了maven-plugin的includeSystemScope标签支持引入系统域,complier-plugin插件主要是解决编译的时候​​source 不能低于1.5​​这个问题。

  1. 回到包的pom.xml所在路径下
mvn clean install -Dmaven.test.skip=true

​ ​​​SpringBoot项目引用离线的包打包正确姿势_spring boot_02

  1. 打包编译
  • 成功标识,可以直接运行这个jar包
    SpringBoot项目引用离线的包打包正确姿势_eureka_03