maven导入第三方jar依赖

前言

本项目是多module的springcloud的项目,因为需要依赖第三方jar包,而客户的部署环境异常无法成功依赖导第三方jar包,所以需要自身项目带上jar包。本项目的hwyg-sms模块(为jar)依赖一些短信的jar,现将第三方的短信jar直接下载放到hwyg-sms模块中。
在这里插入图片描述

1、在模块中导入jar

在这里插入图片描述

2、配置pom
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>com.aliyuncs.dysmsapi</groupId>
            <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/aliyun-java-sdk-dysmsapi-1.1.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.hfocean.common</groupId>
            <artifactId>spring-boot-starter-aliyun-sms</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/spring-boot-starter-aliyun-sms-1.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aliyuncs</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>4.5.20</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/aliyun-java-sdk-core-4.5.20.jar</systemPath>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <includeSystemScope>true</includeSystemScope>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

在这里插入图片描述

3、打包的时候一定要加入以下配置
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <includeSystemScope>true</includeSystemScope>
                    </configuration>
                </plugin>

将scope设置为system表示被依赖项不会从maven仓库中寻找,而是从本地代码中寻找,而且打包的时候可以不用包进去,其他方式会提供次依赖。和compile一样,但是打包时候会exclude此jar。所以要加入此配置表示设置为system的依赖依然会被打包进来。

4、存在的小问题

但是打完war包之后解压包会发现依赖在lib-provided下面,而Tomcat是查询的lib下的依赖,所以还需要新增个配置
在这里插入图片描述

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${project.basedir}/lib</directory>
                            <targetPath>WEB-INF/lib/</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值