0
点赞
收藏
分享

微信扫一扫

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

jjt二向箔 2022-01-12 阅读 18
  • 案例:如下是某一个项目的项目架构

     

  • 使用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}标识取整个项目的绝对路径。

    2. 加入构建插件

      <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这个问题。

    3. 回到包的pom.xml所在路径下

      mvn clean install -Dmaven.test.skip=true
      

       

    4. 打包编译

      • 成功标识,可以直接运行这个jar包

         

举报

相关推荐

0 条评论