一,为什么要集成外部jar包?

不是所有的第三方库都会上传到mvnrepository,

这时我们如果想集成它的第三方库,则需要直接在项目中集成它们的jar包,

在操作上还是很简单的,

这里用luosimao的短信平台sdk演示一下

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,下载并添加到项目

1,下载jar包,
共两个文件:
jersey-bundle-1.19.jar
json-org.jar
 
2,在项目的resources目录下创建jar目录,
把两个jar包文件复制到resources/jar目录下 

项目结构如图:

三,项目中配置pom.xml

配置pom.xml

1,增加jar的依赖
        <!--luosimao send sms begin-->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>api</artifactId>
<version>1.19</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/jersey-bundle-1.19.jar</systemPath>
</dependency> <dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/json-org.jar</systemPath>
</dependency>
<!--luosimao send sms end-->
说明:因为是本地的jar包,不需要作为从maven的仓库里中拉取库文件时的依据
所以groupId/artifactId/version 自己按情况随意填写即可
 
 
2,以plugin增加includeSystemScope
   它的用途是让maven打包时把我们添加的外部jar包也打包时去
   否则maven打包时会漏掉我们手动添加的jar
                <configuration>
<includeSystemScope>true</includeSystemScope>
</configuration> 
效果如下:
    <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>

四,用官方的例子添加一段java代码,并测试效果

1,HomeController.java

@RestController
@RequestMapping("/home")
public class HomeController { //查询剩余短信条数状态
@GetMapping("/status")
public String status() {
//Api api = new Api();
String httpResponse = testStatus();
try {
JSONObject jsonObj = new JSONObject( httpResponse );
int error_code = jsonObj.getInt("error");
if( error_code == 0 ){
int deposit = jsonObj.getInt("deposit");
System.out.println("Fetch deposit success :"+deposit);
}else{
String error_msg = jsonObj.getString("msg");
System.out.println("Fetch deposit failed,code is "+error_code+",msg is "+error_msg);
}
} catch (JSONException ex) {
//Logger.getLogger(Api.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
} return httpResponse;
} //发送并返回对状态的查询
private String testStatus(){
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter(
"api","key-thisisakeydomoforlaoliutest"));
WebResource webResource = client.resource( "http://sms-api.luosimao.com/v1/status.json" );
MultivaluedMapImpl formData = new MultivaluedMapImpl();
ClientResponse response = webResource.get( ClientResponse.class );
String textEntity = response.getEntity(String.class);
int status = response.getStatus();
return textEntity;
}
}

官方的demo代码,我们集成到controller中测试效果

2,测试效果

访问:

http://127.0.0.1:8080/home/status

返回:

{"error":0,"deposit":"88888888"}

返回了剩余的短信条数,说明我们对外部jar包的集成是有效的

六,查看spring boot版本

  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.2.RELEASE)

spring boot:在项目中引入第三方外部jar包集成为本地jar包(spring boot 2.3.2)的更多相关文章

  1. vue-cli项目中引入第三方插件

    前言 最近有小伙伴问道如何在vue-cli项目中引入第三方插件或者库,例如如果想在项目中使用jQuery中的Ajax请求数据呢?或者我想使用Bootstrap框架呢?等等这些问题,本篇博客将带你学习如 ...

  2. vue-cli创建的项目中引入第三方库报错 'caller', 'calle', and 'arguments' properties may not be...

    http://blog.csdn.net/sophie_u/article/details/76223978 以在vue中引入mui第三方库为例: 虽然针对vue,有单独的vue-mui库可以使用,但 ...

  3. vue-cli创建的项目中引入第三方库报错'caller', 'calle', and 'arguments' properties may not be...

    本文链接:https://blog.csdn.net/Sophie_U/article/details/76223978 问题: 在vue的main.js中引入mui.min.js时,报错. 如上,单 ...

  4. vue项目中引入第三方框架

    element-ui npm install element-ui -- save; main.js中 import Element from 'element-ui'; import 'elemen ...

  5. 在Android项目中引入MuPdf

    由于公司手机App要加入一个附件查看功能,需要查看PDF文件,在网上找了许多第三方工具,最后选择了MuPDF. 更多第三方工具可以查看大神总结的:http://www.cnblogs.com/poke ...

  6. Java SE Eclipse中引入第三方jar及class

    使用eclipse开发Java SE 总免不了需要引入第三方的jar或者calss文件.这里给大家说一下如何在eclipse中引入第三方jar或者calss文件. 让我们先了解一下eclipse项目中 ...

  7. 项目中整合第三方插件与SpringMVC数据格式化关于ip地址

    一.Bootstrap 响应式按钮 <div calss="col-sm-2"> <button class="btn btn-default btn- ...

  8. 创建swagger的springboot-stater,并在spring cloud zuul网关中引入

    Swagger 是一款RESTFUL接口的.基于YAML.JSON语言的文档在线自动生成.代码自动生成的工具. 通过在controller中添加注解,即可轻易实现代码文档化. Swagger提供ui界 ...

  9. Laravel Controller中引入第三方类库

    Laravel 引入第三方类库 在Controller中引入自定义的php文件,先在app目录下创建一个新的文件夹,命名Tools(可自定义),接着创建一个MyTest.php: <?php c ...

随机推荐

  1. c,c++变量

    自动变量 局部变量 如不作专门说明为静态变量,都是动态分配存储空间,存储在动态存储区中.这种变量叫自动变量.这种变量只在定义它们的时候才创建,在定义它们的函数返回时系统回收变量所占存储空间.对这些变量 ...

  2. [go语言]-深入理解singleflight

    目录 前言 singleflight使用场景 singleflight 简介 singleflight的使用 从singleflight的test最简单用法 验证并发重复请求 singleflight ...

  3. Pandas 中的遍历与并行处理

    使用 pandas 处理数据时,遍历和并行处理是比较常见的操作了本文总结了几种不同样式的操作和并行处理方法. 1. 准备示例数据 import pandas as pd import numpy as ...

  4. 函数的arguments对象的使用和介绍

    arguments对象用于函数,当不知道传递了多少个实参,就可以使用arguments对象进行存储传递过来的实参(这时不需要写形参). arguments是一个内置对象,也是一个伪数组,我们可以按照数 ...

  5. C语言实现数据机构链表的基本操作(从键盘输入生成链表、读取数组生成链表)

    利用头插法实现逆置 下面简单介绍一下,算法思想结合图示看 算法思想:"删除"头结点与链表其他结点的原有联系(即将头结点的指针置空),再逐个插入逆置链表的表头(即"头插&q ...

  6. 绝了!这款工具让SpringBoot不再需要Controller、Service、DAO、Mapper!

    Dataway介绍 Dataway 是基于 DataQL 服务聚合能力,为应用提供的一个接口配置工具,使得使用者无需开发任何代码就配置一个满足需求的接口.整个接口配置.测试.冒烟.发布,一站式都通过 ...

  7. 性能测试Jmeter安装

    一. Jmeter下载地址: http://jmeter.apache.org/download_jmeter.cgi   二. JDK下载地址: https://www.oracle.com/tec ...

  8. Python-面向网络编程-socket原理

    socket 整个计算机网络是由协议构成,想要通信必须遵守对应的协议,如Web中的http协议.传输协议TCP和UDP等等.在网络工程师的眼中,可能现在网络上的一切都是socket,一切皆socket ...

  9. Centos-修改文件访问和修改时间-touch

    touch 如果文件存在,则改变文件的访问时间和修改时间,如果不存在则创建一个空文件 相关选项 -a   更改文件访问时间为当前系统时间 -m     更改文件修改时间为当前系统时间 -c   如果文 ...

  10. Python练习题 043:Project Euler 015:方格路径

    本题来自 Project Euler 第15题:https://projecteuler.net/problem=15 ''' Project Euler: Problem 15: Lattice p ...