Maven打包时引入本地jar包

技术标签: maven

背景

开发的时用到的jar包可能在私服中找不到,需在下载到本地,然后在编译器Eclipse或者IDEA中引入本地jar包,这样在本地开发是OK的,但是linux服务器通过Maven打包的时候会提示异常找不到对应的类。这是需要在我们的pom.xml文件添加点配置了。

落地

开发支付宝沙箱支付时,需要引入本地jar包,我把jar存放的项目中的/src/main/resources/lib 下
在这里插入图片描述

1.打成war包引入本地jar

在build节点添加配置如下

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<configuration>
			<source>1.8</source>
			<target>1.8</target>
			<encoding>UTF-8</encoding>
			<compilerArguments>
				<extdirs>${project.basedir}/src/main/resources/lib</extdirs>
			</compilerArguments>
	</configuration>
</plugin>

${project.basedir}:表示当前项目的路径,该变量不用配置赋值的;
/src/main/resources/lib :表示我存放j本ar包的路径

2.SpringBoot打成jar包引入本地jar包

原文
后来的后来我把项目由Spring迁移到SpringBoot的时候,发现上传的配置并不能引入本地的jar包。pom文件的修改如下:

1.添加自定义的dependency

<!-- 引入本地jar包:支付宝模块 -->
<dependency>
	<groupId>com.alipay</groupId>
	<artifactId>com-alipay</artifactId>
	<version>1.0</version>
	<scope>system</scope>
          <systemPath>${project.basedir}/src/main/resources/lib/alipay-sdk-java20161213173952.jar</systemPath>
</dependency>
<dependency>
	<groupId>com.alipay.demo</groupId>
	<artifactId>com-alipay-demo</artifactId>
	<version>1.0</version>
	<scope>system</scope>
	<systemPath>${project.basedir}/src/main/resources/lib/alipay-trade-sdk-20161215.jar</systemPath>
</dependency>

scope:需要配置指定为system;
systemPath:指向jar包的地址;
groupId、artifactId、version:可以随意填写,其中artifactId+version就是maven打包后的jar包名

2.在build节点中的builds添加build

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<includeSystemScope>true</includeSystemScope>
	</configuration>
</plugin>

maven打成的jar解压后,在BOOT-INF下的lib目录中可以找到配置引入的jar包。
在这里插入图片描述

来源:网络


智能推荐

SpringBoot 如何手动引入本地的jar包 并利用maven成功打包

背景:  最近公司需要做一个两个系统之前的桥梁 需要用到 甲方爸爸提供的一些jar包 而这些jar包是甲方爸爸自己公司封装的 没有放在maven上 需要我本地引入  我的项目是SpringBoot构建的   在我本地能跑起来 但是打成jar包部署的时候,项目能跑,但是到关键的调用接口的时候就报Java.ClassNofFoundExcep...

maven引入本地jar包并打包——以jna.jar和examples.jar为例

之前引入jar包,在本机运行,一直都没问题,然后我就使用mave打包项目,发现有个包却找不到了。如下图: 可以看到 jar 包是有了的(这两个jar包是本地引入的),但打包却没有进来。 解决:如图: 效果: 最后附上 jna.jar 和 examples.jar的地址: 链接:https://pan.baidu.com/s/10UQCZnlOjEpiscMMh7HLNg 提取码:m07h 复制这段...

Springboot中如何引入本地jar包,并通过maven把项目成功打包成jar包部署

本地jar包 引入到maven项目中 springboot项目 1.在resources中创建lib 加入jar包 2.修改pom文件 注意:重点是systemPath这个路径必须得是你jar的路径。其他的按照套路填就行,要求不是太严格。${project.basedir}只是一个系统自己的常量,不用管它 如何把项目打成jar,同时把本地jar包也引入进去 直接在maven的pom里给spring...

Springboot中如何引入本地jar包,并通过maven把项目成功打包成jar包部署

问题描述 最近尝试引入淘宝SDK,但是打成jar包部署的时候,项目报错,无法运行起来。看了很多种方案,最后做个总结。 解决 如何引入本地jar包 1.在resources下面新建lib文件夹,并把jar包文件放到这个目录下    2.在pom文件定义几个依赖指向刚才引入的文件 <!-- 淘宝SDK -->     <depende...

Springboot中如何引入本地jar包,并通过maven把项目成功打包成jar包部署

springboot项目引用本地jar包 1、首先在resources目录下建立lib目录,引用所需的jar文件。如下图: 2、在pom文件中定义本地jar的引用 注意:引用本地jar文件标签值须指定system,${project.basedir}为系统指定路径。systemPath为本地jar文件的真实路径 如何把项目打成jar,同时把本地jar包也引入进去 直接在maven的pom里给spr...

猜你喜欢

maven项目打包时外部引入jar包无法打到项目中的解决方案

我们在开发一个maven项目时,除了导入maven依赖以外,还经常会引入外部jar包,打包的时候会发现这些jar包根本无法打到项目中去。解决方式有好几种,我这边选择了最简单的一种,就是在pom文件中添加jar包的坐标 groupId和artifactId可以随便填。 打包插件这里要加上configuration 这一步骤,然后运行maven的clean和package命令打包后就会把你外部引入的j...

引入第三方jar包,再最后maven打包时失败

引入第三方jar,maven打包时失败 1、项目架构 2、在项目最后,通过mvn package命令打包的时候,报了一个有关该spirejar包的错误 3、解决办法 ,记得在pom文件中,把这个jar包引入过来。groupId、artifactId、version这几个标签里的内容不太重要,重要的是下面的路径不能引用错 ${basedir} 好像这个代表的是项目的根路径,我不太确定,要是评论区有知...

Maven添加本地jar包,并打包到jar包

首先在项目跟目录创建一个lib文件夹,把本地jar包拷贝到lib文件夹下   image.png 然后在Pom文件中配置   image.png   3.这样的话main方法可以运行项目,但是Maven生成的jar不可以运行,因为本地的jar包没有打包到生成的jar包中,需要如下配置   image.png 转载自:https://www.jianshu.c...

打包、引入jar包

打包包 第一步 打开项目构建 第二步 将模块添加并打包 第三步 选择要打包的模块 第四步 添加后退出,点击要构建的模块就可以了 就可以在OUT文件夹中找到jar包了 引入包 还是第一步 改成点击Libraries 在里面点击引入的jar包 就可以在External Libraries里面看到引入的jar包...

乔坟往事-麦收与秋收

十、麦收与秋收 田家少闲月,五月人倍忙。夜来南风起,小麦覆陇黄。 足蒸暑土气,背灼炎天光,力尽不知热,但惜夏日长。   三月分蘖,四月灌浆,五月麦稍黄。 五月当午前后,麦收季节,牛欢马叫,农人纷忙,学校就放十多天的麦假,并有拾麦之勤工俭学任务。 而四里八乡老师,家里也都是有地的,也要回去收麦子。 于是,这假期也令我们渴望,相比上学日子,虽然干活,总是多些自由。   爷一早就开始...

问答精选

Implicits Confusion

The following polymorphic methods compile: However, if I change the integer 2 to the double 2.0 the compiler complains about not finding an implicit value I have tried to understand some of the other ...

What weaknesses can be found in using Erlang?

I am considering Erlang as a potential for my upcoming project. I need a "Highly scalable, highly reliable" (duh, what project doesn't?) web server to accept HTTP requests, but not really se...

StreamInsight 2.1 adapter to observer

I've been trying to implement the following adapter to connect StreamInsight with BizTalk: http://seroter.wordpress.com/2010/07/09/sending-streaminsight-events-to-biztalk-through-new-web-soaprest-adap...

Exoplayer ui split the screen and add double tap to go forward/backward circular effect

I have to reproduce the following circular effect on the exoplayer. I added two views, exo_rew and exo_ffwd. Which automatically do go back or forward by standard setting. This is the code I've writte...

recipient timezone not working when sending a push notification for AUS, US and Europe

The problem we would like to understand and work around is delivering push notifications to players that are in different timezones and regions, all at the same local time. It would appear the recipie...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答