Maven packs the jar and packs the local jar package, and maven packs the local jar package

1. Problem description

How to package the locally dependent jar package into the jar, as shown in the figure below, the project relies on the SDKs of taobao and pdd, and imports them into the project locally:

insert image description here

    <!-- 淘宝客SDK-->
    <dependency>
      <groupId>taobao</groupId>
      <artifactId>taobao</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${
    
    pom.basedir}/lib/taobao-sdk.jar</systemPath>
    </dependency>

    <!-- 拼多多SDK -->
    <dependency>
      <groupId>pop</groupId>
      <artifactId>pop</artifactId>
      <version>1.11.5</version>
      <scope>system</scope>
     <!-- <systemPath>${
    
    project.basedir}/lib/pop-sdk-1.11.5-all.jar</systemPath>-->
      <systemPath>${
    
    pom.basedir}/lib/pop-sdk-1.11.5-all.jar</systemPath>
    </dependency>

Two, the solution

It depends on what jar package you want to make. If it is a springboot project, package it into a runnable jar and configure it as follows:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

includeSystemScope is set to true, and if it is packaged into a normal jar package, the configuration is as follows:

    <resources>
      <resource>
        <!--本地jar的目录-->
        <directory>lib</directory>
        <!--打包时,目标jar存放位置-->
        <targetPath>BOOT-INF/lib/</targetPath>
        <includes>
          <include>**/*.jar</include>
        </includes>
      </resource>
    </resources>

When the jar package is packaged, the local jar package will be packaged into the BOOT-INF/lib/ directory.

Guess you like

Origin blog.csdn.net/mashangzhifu/article/details/118379676
Recommended