spring boot:在项目中引入第三方外部jar包集成为本地jar包(spring boot 2.3.2)
一,为什么要集成外部jar包?
不是所有的第三方库都会上传到mvnrepository,
这时我们如果想集成它的第三方库,则需要直接在项目中集成它们的jar包,
在操作上还是很简单的,
这里用luosimao的短信平台sdk演示一下
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,下载并添加到项目
项目结构如图:

三,项目中配置pom.xml
配置pom.xml
<!--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-->
<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)的更多相关文章
- vue-cli项目中引入第三方插件
前言 最近有小伙伴问道如何在vue-cli项目中引入第三方插件或者库,例如如果想在项目中使用jQuery中的Ajax请求数据呢?或者我想使用Bootstrap框架呢?等等这些问题,本篇博客将带你学习如 ...
- vue-cli创建的项目中引入第三方库报错 'caller', 'calle', and 'arguments' properties may not be...
http://blog.csdn.net/sophie_u/article/details/76223978 以在vue中引入mui第三方库为例: 虽然针对vue,有单独的vue-mui库可以使用,但 ...
- 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时,报错. 如上,单 ...
- vue项目中引入第三方框架
element-ui npm install element-ui -- save; main.js中 import Element from 'element-ui'; import 'elemen ...
- 在Android项目中引入MuPdf
由于公司手机App要加入一个附件查看功能,需要查看PDF文件,在网上找了许多第三方工具,最后选择了MuPDF. 更多第三方工具可以查看大神总结的:http://www.cnblogs.com/poke ...
- Java SE Eclipse中引入第三方jar及class
使用eclipse开发Java SE 总免不了需要引入第三方的jar或者calss文件.这里给大家说一下如何在eclipse中引入第三方jar或者calss文件. 让我们先了解一下eclipse项目中 ...
- 项目中整合第三方插件与SpringMVC数据格式化关于ip地址
一.Bootstrap 响应式按钮 <div calss="col-sm-2"> <button class="btn btn-default btn- ...
- 创建swagger的springboot-stater,并在spring cloud zuul网关中引入
Swagger 是一款RESTFUL接口的.基于YAML.JSON语言的文档在线自动生成.代码自动生成的工具. 通过在controller中添加注解,即可轻易实现代码文档化. Swagger提供ui界 ...
- Laravel Controller中引入第三方类库
Laravel 引入第三方类库 在Controller中引入自定义的php文件,先在app目录下创建一个新的文件夹,命名Tools(可自定义),接着创建一个MyTest.php: <?php c ...
随机推荐
- Priest John's Busiest Day(POJ 3683)
原题如下: Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12162 ...
- python中一次性input3个整数,并用空格隔开怎么表示
a,b,c=map(int,input('请输入3个整数用空格隔开:').split(' ')) map的使用方法:map(函数名,循环体)
- 第16课 - make的隐式规则(下)
第16课 - make的隐式规则(下) 1
- u深度win10pe装机版制作教程
一款功能强大的u盘启动盘要怎么制作是非常重要的,对于大多数用户来说其中操作步骤并不熟悉.这里小编带来时下最新的u深度win10pe装机版制作教程,教你如何快速的进行u深度U盘的制作,下面就跟小编一起进 ...
- 技术解析丨C++元编程之Parser Combinator
摘要:借助C++的constexpr能力,可以轻而易举的构造Parser Combinator,对用户定义的字符串(User defined literal)释放了巨大的潜力. ## 引子 前不久在C ...
- 005.操作系统及Linux系统,虚拟机的作用和发展历史
操作系统及其作用 操作系统发展史 Linux系统 虚拟机 操作系统 操作系统 操作系统的作用 不同领域的主流操作系统 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有 ...
- ERP与EHR系统的恩怨纠葛--开源软件诞生13
ERP中需要EHR的存在吗--第13篇 用日志记录"开源软件"的诞生 [点亮星标]----祈盼着一个鼓励 博主开源地址: 码云:https://gitee.com/redragon ...
- 报错: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))
你没打开 1.双击打开 2.点击:
- lamda表达式与Stream 流操作,reduce,flatMap,groupingBy等
/** * 符合lambda表达式的接口也叫函数式接口: * 除了默认方法和Object类的方法外,只有一个抽象方法的接口才能符合lambda表达式的要求 * 可以使用@FunctionalInter ...
- You must give at least one requirement to install (see "pip help install")
语言: python why? install 后面没有参数,也就是说没有给想要安装的包 way? pip install 后面要跟想要安装的包名