maven pom.xml 加载本地.jar库文件方法

一般我们使用的jar包,都是从maven仓库中加载的, 那如果是从本地该如何加载呢?

本文介绍maven加载本地jar的方法

在 pom.xml 的 dependencies 节点内增加以下配置即可

XML 复制代码
<dependency> 
    <groupId>cn.tekin</groupId>  
    <artifactId>mylib</artifactId>  
    <version>1.0.0</version>  
    <scope>system</scope>  
	<systemPath>${project.basedir}/lib/mylib_v1.0.0.jar</systemPath>  
</dependency>
复制代码
groupId , artifactId 这个根据你的项目来填写
systemPath 为你的jar文件的本地路径 
${project.basedir}/ 这个为当前项目的根目录路径 变量

完整pom.xml示例

XML 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.tekin</groupId>
    <artifactId>demo-java</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>cn.tekin</groupId>
            <artifactId>mylib</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/mylib_v1.0.0.jar</systemPath>
        </dependency>
    </dependencies>
</project>
相关推荐
暮雨哀尘5 小时前
JAVA基础练习(四):SpringBoot 实现简易登录功能
java·spring boot·eclipse·maven
hanchenxing12 小时前
CI/CD流水线中的构建缓存:从原理到最小可运行示例CI/CD
maven·构建缓存
执明wa1 天前
Android RecyclerView 多类型, 多种 Item
android·xml·开发语言·设计模式·android studio
wl85111 天前
SAP CPI 教程004 如何通过groovy修改XML节点属性值
xml
愛芳芳2 天前
Swagger2 多环境动态配置实战指南
java·后端·maven·springboot·swagger
金玉满堂@bj2 天前
多环境部署方案(开发、测试、生产,搭配Tomcat\+WAR包)
java·tomcat·maven
青春易逝丶2 天前
Maven
java·maven
码匠许师傅3 天前
【C++三方组件】TinyXML2:两个文件的极简 XML 解析器
xml·c++
yuzhiboyouye4 天前
my-batisPlus什么时候用xml什么时候用mapper自带的方法,这两种写法专业一点叫什么,什么场景分别使用
xml