欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Maven项目中如何引入本地的jar包或者sdk

程序员文章站 2022-03-25 08:14:30
...

Maven项目中如何引入本地的jar包或者sdk

1、没有导入的时候

package com.xjj.controller;


import com.xjj.service.InterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Date 2020/3/14 10:58
 * @author xjj
 */
@Controller
@RequestMapping("/interface")
public class InterfaceController {
    @Autowired
    private InterfaceService interfaceService;

    public void test(){
        AlipayClient alipayClient = new DefaultAlipayClient("asd", "asd", "asd", "json", "asd", "asd", "asd");
    }

}

Maven项目中如何引入本地的jar包或者sdk

2、创建lib文件夹,并向其中引入需要的文件

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zR4BalWD-1584787340425)(C:\Users\徐敬杰\Desktop\assets\1584787024595.png)]

3、在pom.xml文件中添加路径,其中的groupId和artifactId,version等信息可以随便填写,主要是路径一定要填写正确

<dependency>
  <groupId>com.ali</groupId>
  <artifactId>pay</artifactId>
  <version>1.0</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/alipay-sdk-java20170324180803.jar</systemPath>
</dependency>

4、然后会自动的引入我们需要的依赖

package com.xjj.controller;


import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.xjj.service.InterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Date 2020/3/14 10:58
 * @author xjj
 */
@Controller
@RequestMapping("/interface")
public class InterfaceController {
    @Autowired
    private InterfaceService interfaceService;

    public void test(){
        AlipayClient alipayClient = new DefaultAlipayClient("asd", "asd", "asd", "json", "asd", "asd", "asd");
    }

}

![成功以后的截图](https://img-blog.csdnimg.cn/20200321184318129.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTUwMTgzMA==,size_16,color_FFFFFF,t_70)
相关标签: 软件