maven项目引入外部依赖jar包

maven项目引入外部依赖jar包

1.创建lib文件夹,将自己需要的jar包放进去,选中lib包,点击鼠标右键,选择add as library,点击后jar包左侧会有个三角形箭头。

在这里插入图片描述

2.pom文件中添加依赖,此处以fastjson-1.1.41.jar举例。

<dependency>
     <groupId>fastjson</groupId>		//可以随便写,一般写真实groupId
     <artifactId>fastjson</artifactId>	//可以随便写,一般写jar包名称
     <scope>system</scope>				
     <version>1.1.41</version>			//可以随便写,最好写真实版本
     <systemPath>${pom.basedir}/lib/fastjson-1.1.41.jar</systemPath>  
     //${pom.basedir} 代表根目录,地址正确的话,ctrl+鼠标左键可以直接点过去,这里填对应jar包的路径
 </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-2.2.2</artifactId>
            <scope>system</scope>
            <version>2.2.2</version>
            <systemPath>${pom.basedir}/lib/cglib-2.2.2.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <scope>system</scope>
            <version>1.6.1</version>
            <systemPath>${pom.basedir}/lib/dom4j-1.6.1.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>fastjson</groupId>
            <artifactId>fastjson</artifactId>
            <scope>system</scope>
            <version>1.1.41</version>
            <systemPath>${pom.basedir}/lib/fastjson-1.1.41.jar</systemPath>
        </dependency>

3.打包时也要打进去,添加相关配置

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                    //只需要在<configuration>中额外添加下面这一行即可
                    <includeSystemScope>true</includeSystemScope>	
                </configuration>
            </plugin>
        </plugins>
    </build>

4.引入后测试,能成功使用fastjson相关代码。

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class ImportJarTest {

    public static void main(String[] args) {
        String data = "{\n" +
                "    \"name\": \"张三\",\n" +
                "    \"age\": \"23\"\n" +
                "}";
        JSONObject json = JSON.parseObject(data);
        Object name = json.get("name");
        System.out.println(name);
    }
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值