Maven:把本地Jar包引入到SpringBoot项目中

实现

  1. 把jar包放到项目中如libs

  2. pom.xml中的dependencies中引入Jar包:

        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.0.6</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/extentreports-3.0.6.jar</systemPath>
        </dependency>
  1. pom.xml中的build-->plugins-->plugin-->spring-boot-maven-plugin中添加配置,如下:
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- 引入本地jar包 -->
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
</build>
  1. 在Dockerfile中把Jar包复制到容器内(没有则忽略)

  2. (理论上不需执行,这里只作为备份放在这里)在pom.xml中的build中添加resources配置,如下:

<build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!-- 引入本地jar包配置 -->
            <resource>
                <directory>src/main/resources</directory>
                <targetPath>/BOOT-INF/lib/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.jpg</include>
                    <include>**/*.ttf</include>
                    <include>**/*.xml</include>
                    <include>**/*.html</include>
                    <include>**/*.css</include>
                    <include>**/*.js</include>
                    <include>**/*.ftl</include>
                    <include>**/*.TTF</include>
                </includes>
                <excludes>
                    <exclude>**/*.jmx</exclude>
                </excludes>
            </resource>
        </resources>
</build>

参考资料

posted @ 2023-07-25 16:37  Feng1024  阅读(294)  评论(0编辑  收藏  举报