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

2.pom文件中添加依赖,此处以fastjson-1.1.41.jar举例。
<dependency>
<groupId>fastjsongroupId> //可以随便写,一般写真实groupId
<artifactId>fastjsonartifactId> //可以随便写,一般写jar包名称
<scope>systemscope>
<version>1.1.41version> //可以随便写,最好写真实版本
<systemPath>${pom.basedir}/lib/fastjson-1.1.41.jarsystemPath>
//${pom.basedir} 代表根目录,地址正确的话,ctrl+鼠标左键可以直接点过去,这里填对应jar包的路径
dependency>
<dependency>
<groupId>cglibgroupId>
<artifactId>cglib-2.2.2artifactId>
<scope>systemscope>
<version>2.2.2version>
<systemPath>${pom.basedir}/lib/cglib-2.2.2.jarsystemPath>
dependency>
<dependency>
<groupId>dom4jgroupId>
<artifactId>dom4jartifactId>
<scope>systemscope>
<version>1.6.1version>
<systemPath>${pom.basedir}/lib/dom4j-1.6.1.jarsystemPath>
dependency>
<dependency>
<groupId>fastjsongroupId>
<artifactId>fastjsonartifactId>
<scope>systemscope>
<version>1.1.41version>
<systemPath>${pom.basedir}/lib/fastjson-1.1.41.jarsystemPath>
dependency>
3.打包时也要打进去,添加相关配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
exclude>
excludes>
//只需要在<configuration>中额外添加下面这一行即可
<includeSystemScope>trueincludeSystemScope>
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);
}
}