Maven中使用本地JAR包
在Maven项目中使用本地JAR包有两种方法:
1. 使用system scope

<dependencies>
<dependency>
<groupId>org.richard</groupId>
<artifactId>my-jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/my-jar.jar</systemPath>
</dependency>
</dependencies>

system scope引入的包,在使用jar-with-dependencies打包时将不会被包含,可以使用resources将本地包打进jar-with-dependencies

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>xxx-jar-with-dependencies</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>lib/</targetPath>
<directory>lib/</directory>
<includes>
<include>**/my-jar.jar</include>
</includes>
</resource>
</resources>
</build>

生成的xxx-jar-with-dependencies.jar中,将会包含lib目录以及my-jar.jar,并且能够被在执行的时候被找到。
有的时候这种方法会实效,比如JDBCDriver在声明的时候Class.forName("xxx.Driver")就会说找不到类,用下面两种方法就可以。
2. 将jar包安装到本地repository中
mvn install:install-file -Dfile=my-jar.jar -DgroupId=org.richard -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar
3. 添加 in project repository,在新机器上执行时就不用运行mvn install:install-file命令了

<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/lib</url>
</repository> <dependency>
<groupId>org.richard</groupId>
<artifactId>my-jar</artifactId>
<version>1.0</version>
</dependency>

你的jar包及路径必须严格遵循格式:
/groupId/artifactId/version/artifactId-verion.jar
本例中: lib/org/richard/my-jar/1.0/my-jar-1.0.jar
Maven中使用本地JAR包的更多相关文章
- Maven中安装本地Jar包到仓库中或将本地jar包上传
摘要 maven install 本地jar 命令格式 mvn install:install-file -DgroupId=<group_name> -DartifactId=<a ...
- 在maven中引入本地jar包的方法
一.第一种方式: 1.电脑安装maven 2.下载jar.例如 gj.jar 3.把jar随便放一个位置 4.在jar包目录下打开cmd输入: mvn install:install-file -Df ...
- 向maven中添加本地jar包
<dependency> <groupId>org.csource</groupId> <artifactId>fastdfs-client-java& ...
- 如何在maven中添加本地jar包
mvn install:install-file -DgroupId=mytest-DartifactId=test-Dversion=1.1 -Dpackaging=jar -Dfile=d:\te ...
- maven pom 引入本地jar包
maven pom 引入本地jar包 在pom.xml同级目录下新建lib文件夹,并放入本地jar包. 配置Jar包的dependency,包括groupId,artifactId,version三个 ...
- springboot(六) Maven打包引入本地jar包
springboot Maven打包引入本地jar包 最近在做项目的时候,有一些jar包不存在maven的依赖库中,所以需要自己引入本地jar包来达到需求,那么我们该如何去将本地的jar包引入s ...
- idea在maven中引入了jar包依赖,但是编译过程中报出XXX程序包不存在,已解决
idea在maven中引入了jar包依赖,但是编译过程中报出XXX程序包不存在 1. 报错具体情况 2. Project Structure中的Libraries没有任何红色波浪线 3. 发现自己要引 ...
- (转)如何在maven的pom.xml中添加本地jar包
1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下所示: 1 groupId 2 artifactId 3 version 4 jar包的依赖 如果要将 ...
- (转)如何在maven的pom.xml中添加本地jar包
转载自: https://www.cnblogs.com/lixuwu/p/5855031.html 1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下 ...
随机推荐
- php中按值传递和按引用传递的一个问题
php中传递变量默认是按照值传递. 简单举个例子: <?php function testArray($arr){// &$arr $arr = array(1,2,3,); } $ar ...
- IIC双向电平转换电路设计
现代的集成电路工艺加工的间隙可达0.5μm 而且很少限制数字I/O 信号的最大电源电压和逻辑电平. 为了将这些低电压电路与已有的5V或其他I/O电压器件连接起来,接口需要一个电平转换器.对于双向的总线 ...
- Codeforces 718C solution
C. Sasha and Array time limit per test : 5 seconds memory limit per test : 256 megabytes Descrip ...
- 汇编 指令lodsb,lodsw,lodsd
知识点: 汇编指令 lodsb,lodsw,lodsd 一.汇编指令LODSB //scasb scasw scasd //stosb stosw stosd 1. __asm lodsb //作用 ...
- Python 学习 第九篇:模块
模块是把程序代码和数据封装的Python文件,也就是说,每一个以扩展名py结尾的Python源代码文件都是一个模块.每一个模块文件就是一个独立的命名空间,用于封装顶层变量名:在一个模块文件的顶层定义的 ...
- Visual Studio2017 Remote Debugger
前言 大家在使用vs打包后的文件部署到服务器后,有时候我们需要对线网的后台进行调试.但是它不像在VS中.这个时候我们该怎么调试呢? 微软想到了这一点,他们在 VS 中给我们提供了一个功能: Remot ...
- iphone忘记锁屏密码却记得appleID密码的不保存数据的刷机办法
请注意看清题目再看本文,另外一切后果博主不负任何责任.操作实现环境:原装数据线,拔掉sim卡昨天,iPhone6sp忘记密码被锁定,尝试通过找回手机抹除手机功能后,提示需要手机接入互联网才能实现,而我 ...
- Ceph分布式存储-运维操作笔记
一.Ceph简单介绍1)OSDs: Ceph的OSD守护进程(OSD)存储数据,处理数据复制,恢复,回填,重新调整,并通过检查其它Ceph OSD守护程序作为一个心跳 向Ceph的监视器报告一些检测信 ...
- nginx try_files 详解
server { listen ; server_name localhost; index index.html index.htm index.php; root /data/wwwroot; l ...
- Safecracker-HDU1015
题意 给你大写字母的字符串,A=1,...Z=26,以及target 问你是否有v - w^2 + x^3 - y^4 + z^5 = target 有输出字典序大的那个字符串 分析 dfs code ...