Springboot 自定义jar包


目录

摘要

开发springboot项目过程中,有时需要依赖仓库中没有发布的第三方jar包,有以下方案可供选择

一、方法1

在pom.xml增加插件配置,指定当前项目所依赖的jar包目录

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
            <compilerArguments>
            <extdirs>${basedir}/libs</extdirs>
        </compilerArguments>
    </configuration>
</plugin>

指定springboot运行时依赖

<resources>
    <resource>
        <filtering>true</filtering>
        <directory>${basedir}/src/main/resources</directory>
        <includes>
            <include>**/application*.yml</include>
            <include>**/application*.properties</include>
        </includes>
    </resource>
    <resource>
        <directory>${basedir}/src/main/resources</directory>
        <excludes>
            <exclude>**/application*.yml</exclude>
            <exclude>**/application*.properties</exclude>
        </excludes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <targetPath>BOOT-INF/lib/</targetPath>
        <includes>
            <include>**/*.jar</include>
        </includes>
    </resource>
</resources>

二、方法2

添加dependency依赖,使用systemPath属性,scope属性值为system

<dependency>
    <groupId>xxxx</groupId>
    <artifactId>xxxxx</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/xxxx-bbbb.jar</systemPath>
</dependency>

修改打包配置,将自定义jar包包含进去

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

文章作者: 一剑潇
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 一剑潇 !
  目录
{% if theme.mermaid.enable %} {% endif %}